<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 头部操作栏 -->
            <form class="layui-form">
                <div class="layui-form lay-header">
                    <div class="toolbar">
                        <div class="layui-form-item lay-query-content">
                            <div class="lay-query-box">
                                <div class="query-lt">
                                    <div class="layui-inline">
                                        <label class="layui-form-label">订单来源：</label>
                                        <div class="layui-input-inline">
                                            <select name="orderSource">
                                                <option value="">请选择</option>
                                                <option value="staff">自主录入/员工录入</option>
                                                <option value="platform">云端制造/平台指派</option>
                                                <option value="agent">渠道录入/代理商录入</option>
                                                <option value="customer">云端智采/客户直接委派</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">订单状态：</label>
                                        <div class="layui-input-inline">
                                            <select name="status">
                                                <option value="">请选择</option>
                                                <option value="pending">待提交</option>
                                                <option value="accept">待受理</option>
                                                <option value="review">待评审</option>
                                                <option value="refuse">不接单</option>
                                                <option value="offer">待报价</option>
                                                <option value="tosign">待签约</option>
                                                <option value="signed">已签约</option>
                                                <option value="finish">已完成</option>
                                                <option value="over">已关闭</option>

                                            </select>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">客户名称：</label>
                                        <div class="layui-input-inline">
                                            <input name="customerName" class="layui-input" type="text"
                                                   placeholder="请输入客户名称"/>
                                        </div>
                                    </div>
                                    <div class="layui-inline">
                                        <label class="layui-form-label">订单编号：</label>
                                        <div class="layui-input-inline">
                                            <input name="code" class="layui-input" type="text" placeholder="请输入订单编号"/>
                                        </div>
                                    </div>
                                </div>
                                <div class="query-rt">
                                    <div class="layui-inline">
                                        <button type="button" class="layui-btn icon-btn color-green"
                                                lay-filter="formSubSearchLog" lay-submit type="button">查询
                                        </button>
                                        <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit
                                                type="button">
                                            重置
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="lay-btn-rows">
                        <div class="lay-btn-box">
                            <div class="lay-btn-lt">
                                <button id="inquiryOrderInformationBtnAdd" class="layui-btn icon-btn color-reseda" type="button">
                                    添加正式打样订单
                                </button>
                            </div>
                            <div class="lay-btn-rt">
                            </div>
                        </div>
                    </div>
                </div>
            </form>
            <!-- 表格 -->
            <table class="layui-table" id="orderTable" lay-filter="orderTable"></table>
        </div>
    </div>
</div>

<style>
    .open-details-box::-webkit-scrollbar {
        width: 0 !important
    }

    div[lay-id="inquiryOrderOfferTable"] .layui-form,
    div[lay-id="inquiryOrderOfferTable"] .layui-table-box,
    div[lay-id="inquiryOrderOfferTable"] .layui-table-body,
    div[lay-id="inquiryOrderOfferTable"] .layui-table-cell,
    div[lay-id="inquiryOrderInformationTable"] .layui-form,
    div[lay-id="inquiryOrderInformationTable"] .layui-table-box,
    div[lay-id="inquiryOrderInformationTable"] .layui-table-body,
    div[lay-id="inquiryOrderInformationTable"] .layui-table-cell,
    div[lay-id="inquiryOrderExamineTable"] .layui-form,
    div[lay-id="inquiryOrderExamineTable"] .layui-table-box,
    div[lay-id="inquiryOrderExamineTable"] .layui-table-body,
    div[lay-id="inquiryOrderExamineTable"] .layui-table-cell,
    div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-form,
    div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-box,
    div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-body,
    div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-cell,
    div[lay-id="inquiryReviewResultTable"] .layui-form,
    div[lay-id="inquiryReviewResultTable"] .layui-table-box,
    div[lay-id="inquiryReviewResultTable"] .layui-table-body,
    div[lay-id="inquiryReviewResultTable"] .layui-table-cell {
        overflow: visible;
        padding: 0 1px;
    }


    div[lay-id="inquiryOrderOfferTable"] .layui-table-cell,
    div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-cell,
    div[lay-id="inquiryReviewResultTable"] .layui-table-cell {
        overflow: visible;
        padding: 10px;
    }


    div[lay-id="inquiryOrderOfferTable"] .layui-table-cell,
    div[lay-id="inquiryReviewResultTable"] .layui-table-cell,
    div[lay-id="inquiryOrderExamineOrderProReviewTable"] .layui-table-cell,
    div[lay-id="inquiryOrderInformationTable"] .layui-table-cell,
    div[lay-id="inquiryOrderDetailsTable"] .layui-table-cell,
    div[lay-id="inquiryOrderExamineTable"] .layui-table-cell,
    div[lay-id="inquiryOrderQuotationRecordDetailsTable"] .layui-table-cell {
        height: auto;
        overflow: visible;
    }

    /*inquiryOrderOfferForm*/
    form[lay-filter="inquiryOrderDetailsForm"] .layui-row label,
    form[lay-filter="inquiryOrderExamineForm"] .layui-row label,
    form[lay-filter="inquiryOrderInformationForm"] .layui-row label,
    .inquiryOrderBox .layui-row label {
        width: 90px;
        padding: 9px;
    }

    .inquiryOrderBox .layui-form-item .layui-inline,
    form[lay-filter="inquiryOrderDetailsForm"] .layui-form-item .layui-inline,
    form[lay-filter="inquiryOrderExamineForm"] .layui-form-item .layui-inline,
    form[lay-filter="inquiryOrderInformationForm"] .layui-form-item .layui-inline {
        margin-right: 0;
    }

    form[lay-filter="inquiryOrderInformationForm"] .layui-form-item .layui-form-mid,
    form[lay-filter="inquiryOrderDetailsForm"] .layui-form-item .layui-form-mid {
        padding: 9px 0 0 !important;
    }


    .inquiryOrderBox .layui-input-inline input[readonly],
    .inquiryOrderBox .layui-input-inline input[readonly]:hover,
    .inquiryOrderBox .layui-input-inline input[readonly]:focus,
    form[lay-filter="inquiryOrderDetailsForm"] input[readonly],
    form[lay-filter="inquiryOrderDetailsForm"] input[readonly]:hover,
    form[lay-filter="inquiryOrderDetailsForm"] input[readonly]:focus,
    form[lay-filter="inquiryOrderExamineForm"] .layui-inline input[readonly],
    form[lay-filter="inquiryOrderExamineForm"] .layui-inline input[readonly]:hover,
    form[lay-filter="inquiryOrderExamineForm"] .layui-inline input[readonly]:focus {
        border-color: transparent !important;
        outline-color: transparent;
    }


    .inquiryOrderReviewForm-title {
        width: 100%;
    }

    .inquiryOrderReviewForm-title .title {
        display: inline-block;
        font-size: 16px;
        font-weight: bold;
        color: #333333;
        line-height: 19px;
        position: relative;
        padding: 6px 0 19px 0;
    }

    .inquiryOrderReviewForm-title .title:after {
        content: '';
        display: block;
        position: absolute;
        left: 0;
        bottom: 0;
        width: calc(100% + 6px);
        height: 3px;
        background: #0A8B0A;
    }

    .line {
        width: 100%;
        height: 1px;
        background-color: #F8F8F8;
    }

    [lay-filter="contractForm"] .layui-form-label,
    [lay-filter="contractChangeRecordForm"] .layui-form-label {
        width: 100px;
    }

    [lay-filter="contractForm"] .layui-input-block,
    [lay-filter="contractChangeRecordForm"] .layui-input-block {
        margin-left: 130px;
    }

    .preview {
        cursor: pointer;
        float: left;
    }

    .download {
        cursor: pointer;
        float: right;
    }

    .file-a {
        font-size: 12px;
        word-break: break-all;
        text-overflow: ellipsis;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        margin-top: 5px;
    }

    .info_row {
        height: 30px;
        line-height: 30px;
    }

    .attachments {
        cursor: pointer;
        display: block;
        float: left;
        overflow: hidden;
        text-align: center;
        padding: 0 10px;
        width: 100px;
    }
</style>

<!-- 表格操作列 -->
<script type="text/html" id="orderTableBar">
    <a class="layui-btn layui-btn-xs color-green" lay-event="details">详情</a>
    {{# if(d.orderRoot!="formal"){  }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="acceptance">受理</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="review">评审</a>
    {{# } }}
    {{# if(d.orderRoot=="formal"){  }}
    <a class="layui-btn layui-btn-xs" lay-event="offer">报价</a>
    {{# } }}
    <a class="layui-btn layui-btn-xs" lay-event="quotationRecord">报价记录</a>
    <a class="layui-btn layui-btn-xs" lay-event="contract">合同</a>

    {{# if(d.status!="finish"){  }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="closure">结案</a>
    {{# } }}


</script>

<!--添加询价订单信息-->
<!--inquiryOrderInformation-->
<script type="text/html" id="inquiryOrderInformationForm">
    <form lay-filter="inquiryOrderInformationForm" class="layui-form model-form"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box"
             style="height: calc(100% - 100px); padding-top: 20px;overflow: auto;margin-bottom: 20px">
            <div class="layui-form-item layui-row">
                <input name="id" type="hidden"/>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户名称</label>
                    <div class="layui-input-inline">
                        <select name="customerId" lay-filter="customerId" lay-verify="required" lay-search=""></select>
                    </div>
                    <div class="layui-word-aux layui-form-mid">
                        <button class="layui-btn layui-btn-xs" id="addCustomerBtn">添加</button>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户联系人</label>
                    <div class="layui-input-inline">
                        <select name="customerContactsId" lay-filter="customerContactsId" lay-verify="required" lay-search=""></select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">联系人电话</label>
                    <div class="layui-input-inline">
                        <input name="customerContactsPhone" class="layui-input" type="text" placeholder="请输入联系人电话"
                               lay-verify="numbers"/>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">交货时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="deliveryTime" placeholder="交货时间"
                               lay-verify="required" name="deliveryTime">
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属渠道</label>
                    <div class="layui-input-inline">
                        <select name="channelId" lay-search=""></select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">订单类型</label>
                    <div class="layui-input-inline">
                        <select name="orderType" lay-verify="required" disabled>
                            <option value="proff">打样订单</option>
                            <!--<option value="trial">试产订单</option>
                            <option value="mass">量产订单</option>-->
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <input name="checkerName" type="hidden"/>
                    <label class="layui-form-label">询价审核人</label>
                    <div class="layui-input-inline">
                        <select name="checkerId" lay-verify="required" lay-filter="checkerId" lay-search=""></select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">订单来源</label>
                    <div class="layui-input-inline">
                        <select name="orderSource">
                            <option value="staff">自主录入/员工录入</option>
                            <option value="platform">云端制造/平台指派</option>
                            <option value="agent">渠道录入/代理商录入</option>
                            <option value="customer">云端智采/客户直接委派</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价截止时间</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="offerEndTime" placeholder="交货时间"
                               lay-verify="required" name="offerEndTime">
                    </div>
                </div>
                <div class="layui-inline layui-col-md3" id="contractIdBox" style="display:none;">
                    <label class="layui-form-label">选择合同</label>
                    <div class="layui-input-inline">
                        <select name="contractId" lay-filter="contractId" lay-verify="required" lay-search=""></select>
                    </div>
                    <div class="layui-word-aux layui-form-mid">
                        <button class="layui-btn layui-btn-xs" id="contractIdAddBtn">添加</button>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="inquiryOrderInformationTable"
                       lay-filter="inquiryOrderInformationTable"></table>
            </div>
            <div class="layui-form-item" style="padding-top: 20px">
                <label class="layui-form-label">备注说明</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" class="layui-textarea" style="resize: none" name="remark"></textarea>
                </div>

            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="inquiryOrderInformationSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--添加询价订单信息  添加物料-->
<!--inquiryOrderInformation-->
<script type="text/html" id="inquiryOrderInformationFormToolbar">
    <a class="layui-btn" lay-event="addProduct">添加物料</a>
</script>

<!--添加询价订单信息  删除-->
<script type="text/html" id="inquiryOrderInformationFormBar">
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
</script>

<!-- 添加客户表单弹窗 -->
<script type="text/html" id="customersInfoForm">
    <form lay-filter="customersInfoForm" class="layui-form model-form"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow-y: auto">
            <input name="id" type="hidden"/>
            <input name="approverName" id="approverNameHidden" type="hidden"/>
            <input name="salesmanName" id="salesmanNameHidden" type="hidden"/>
            <div class="layui-form-item">
                <label class="layui-form-label">客户类型</label>
                <div class="layui-input-inline">
                    <select name="customerType" id="customerType">
                        <option value="">请选择</option>
                        <option value="Intended">意向客户</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属代理商</label>
                <div class="layui-input-inline">
                    <select name="selAgtId" lay-search></select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>客户名称</label>
                <div class="layui-input-inline">
                    <input name="customerName" placeholder="请输入客户名称" type="text" class="layui-input"
                           lay-verify="required"
                           required/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>营业执照号</label>
                <div class="layui-input-inline">
                    <input name="licenseNo" placeholder="请输入营业执照号" type="text" class="layui-input" lay-verify="required"
                           required/>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">省</label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="provinceName"/>
                        <select name="province" id="province" lay-filter="province"></select>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">市</label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="cityName"/>
                        <select name="city" id="city" lay-filter="city"></select>
                    </div>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-form-item">
                    <label class="layui-form-label">区</label>
                    <div class="layui-input-inline">
                        <input type="hidden" name="areaName"/>
                        <select name="area" id="area" lay-filter="area"></select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">详情地址</label>
                <div class="layui-input-inline">
                    <input name="address" placeholder="请输入详情地址" type="text" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>联系人姓名</label>
                <div class="layui-input-inline">
                    <input name="contactName" placeholder="请输入联系人姓名" type="text" class="layui-input"
                           lay-verify="required"
                           required/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>职务</label>
                <div class="layui-input-inline">
                    <select name="job">
                        <option value="">请选择</option>
                        <option value="iegalperson">法人</option>
                        <option value="ceo">总经理/总裁</option>
                        <option value="business">业务负责人</option>
                        <option value="finance">财务负责人</option>
                        <option value="purchase">采购负责人</option>
                        <option value="salesman">业务专员</option>
                        <option value="other">其他</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属部门</label>
                <div class="layui-input-inline">
                    <input name="department" placeholder="请输入所属部门" type="text" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">名片</label>
                <div class="layui-input-inline">
                    <div id="btnUpload15" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传文件
                    </div>
                    <div id="btnUpload15_path" style="margin-left: 150px;line-height: 40px;"></div>
                    <input id="btnUpload15_file" name="visitingCard" type="hidden"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>电话</label>
                <div class="layui-input-inline">
                    <input name="telephone" placeholder="请输入电话" type="text" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">微信号</label>
                <div class="layui-input-inline">
                    <input name="wechatNumber" placeholder="请输入微信号" type="text" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                    <input name="email" placeholder="请输入邮箱" type="text" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>线索来源</label>
                <div class="layui-input-inline">
                    <select name="source">
                        <option value="">请选择</option>
                        <option value="meet">线下会面</option>
                        <option value="activities">线下活动</option>
                        <option value="collect">线上搜集</option>
                        <option value="introduce">客户介绍</option>
                        <option value="consulting">网络咨询</option>
                        <option value="taobao">淘宝</option>
                        <option value="other">其他</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">推荐人</label>
                <div class="layui-input-inline">
                    <input name="referees" placeholder="请输入推荐人" type="text" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">年用刀量</label>
                <div class="layui-input-inline">
                    <input name="dosage" placeholder="请输入年用刀量" type="text" class="layui-input"/>
                </div>
                <div class="layui-form-mid layui-word-aux">单位：万元</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">业务员</label>
                <div class="layui-input-inline">
                    <select name="salesmanId" lay-filter="salesman" lay-search></select>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">审批人</label>
                <div class="layui-input-inline">
                    <select name="approver" lay-filter="approver" lay-search></select>
                </div>
            </div>

        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="customersInfoFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 询价订单详情 -->
<!--inquiryOrderDetails-->
<script type="text/html" id="inquiryOrderDetailsForm">
    <form lay-filter="inquiryOrderDetailsForm" class="layui-form model-form"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
            <div class="layui-form-item layui-row">
                <input name="id" type="hidden"/>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户联系人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">联系人电话:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsPhone" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">交货时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="deliveryTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属渠道:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="channelName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">订单录入人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="orderCreatorName" readonly>
                    </div>
                </div>
                <!--<div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属部门:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="departmentName" readonly>
                    </div>
                </div>-->
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">提交时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="createTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价截止时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="offerEndTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价受理人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="checkerName" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="inquiryOrderDetailsTable" lay-filter="inquiryOrderDetailsTable"></table>
            </div>

        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="inquiryOrderDetailsSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 订单物料列表 操作-->
<!--inquiryOrderDetails-->
<script type="text/html" id="inquiryOrderDetailsExamineBar">
    {{# if(d.status=="pending"){  }}
    <a class="layui-btn layui-btn-xs" lay-event="examine">审核</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="inquiryOrderDetailsExamineDetails">详情</a>
    {{# } }}
</script>

<!--询价订单评审 操作-->
<!--inquiryOrderDetailsReviewBar-->
<script type="text/html" id="inquiryOrderDetailsReviewBar">
    {{# if(d.finalResult == 'unhandled'){  }}
    <a class="layui-btn layui-btn-xs" lay-event="review">评审结果</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="reviewDetails">详情</a>
    {{# } }}

</script>

<!-- 订单物料列表 审核界面 -->
<!--inquiryOrderExamine-->
<script type="text/html" id="inquiryOrderExamineForm">
    <form lay-filter="inquiryOrderExamineForm" class="layui-form model-form"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
            <div class="layui-form-item layui-row">
                <input name="id" type="hidden"/>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户联系人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">联系人电话:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsPhone" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">交货时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="deliveryTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属渠道:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="channelName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">订单录入人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="orderCreatorName" readonly>
                    </div>
                </div>
                <!--<div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属部门:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="departmentName" readonly>
                    </div>
                </div>-->
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">提交时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="createTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价截止时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="offerEndTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价受理人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="checkerName" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="inquiryOrderExamineTable" lay-filter="inquiryOrderExamineTable"></table>
            </div>
            <div class="layui-form-item" id="inquiryOrderExamineOrderProReviewBox" style="display: none">
                <button class="layui-btn" type="button" id="inquiryOrderExamineOrderProReviewAdd">添加评审环节</button>
                <table class="layui-table" id="inquiryOrderExamineOrderProReviewTable"
                       lay-filter="inquiryOrderExamineOrderProReviewTable"></table>
            </div>

        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="inquiryOrderExamineSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 订单物料列表 询价订单评审 -->
<!--inquiryOrderReview-->
<script type="text/html" id="inquiryOrderReviewForm">
    <form lay-filter="inquiryOrderReviewForm" class="layui-form model-form inquiryOrderBox"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
            <div class="layui-form-item layui-row">
                <input name="id" type="hidden"/>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户联系人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">联系人电话:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsPhone" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">交货时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="deliveryTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属渠道:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="channelName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">订单录入人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="orderCreatorName" readonly>
                    </div>
                </div>
                <!--<div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属部门:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="departmentName" readonly>
                    </div>
                </div>-->
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">提交时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="createTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价截止时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="offerEndTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价受理人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="checkerName" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="inquiryOrderReviewForm-title">
                    <h3 class="title">订单信息</h3>
                </div>
                <div class="line"></div>
                <table class="layui-table" id="inquiryOrderReviewTable" lay-filter="inquiryOrderReviewTable"></table>
            </div>

            <div class="layui-form-item">
                <div class="inquiryOrderReviewForm-title">
                    <h3 class="title">评审环节</h3>
                </div>
                <div class="line"></div>
                <table class="layui-table" id="inquiryReviewLinkTable" lay-filter="inquiryReviewLinkTable"></table>
            </div>

            <div class="layui-form-item">
                <div class="inquiryOrderReviewForm-title">
                    <h3 class="title">终审结果</h3>
                </div>
                <div class="line"></div>
                <table class="layui-table" id="inquiryReviewResultTable" lay-filter="inquiryReviewResultTable"></table>
            </div>

        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="inquiryOrderReviewSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 订单物料列表 询价订单报价 -->
<!--inquiryOrderOffer-->
<script type="text/html" id="inquiryOrderOfferForm">
    <form lay-filter="inquiryOrderOfferForm" class="layui-form model-form inquiryOrderBox"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
            <div class="layui-form-item layui-row">
                <input name="id" type="hidden"/>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户联系人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">联系人电话:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsPhone" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">交货时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="deliveryTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属渠道:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="channelName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">订单录入人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="orderCreatorName" readonly>
                    </div>
                </div>
                <!--<div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属部门:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="departmentName" readonly>
                    </div>
                </div>-->
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">提交时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="createTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价截止时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="offerEndTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价受理人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="checkerName" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="inquiryOrderOfferTable" lay-filter="inquiryOrderOfferTable"></table>
            </div>

        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="inquiryOrderOfferSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--订单物料列表 报价记录-->
<!--inquiryOrderQuotationRecord-->
<script type="text/html" id="inquiryOrderQuotationRecordForm">
    <form lay-filter="inquiryOrderQuotationRecordForm" class="layui-form model-form inquiryOrderBox"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
            <div class="layui-form-item layui-row">
                <input name="id" type="hidden"/>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户联系人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">联系人电话:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsPhone" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">交货时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="deliveryTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属渠道:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="channelName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">订单录入人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="orderCreatorName" readonly>
                    </div>
                </div>
                <!--<div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属部门:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="departmentName" readonly>
                    </div>
                </div>-->
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">提交时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="createTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价截止时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="offerEndTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价受理人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="checkerName" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="inquiryOrderQuotationRecordTable"
                       lay-filter="inquiryOrderQuotationRecordTable"></table>
            </div>

        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!--订单物料列表 报价记录  操作-->
<!--inquiryOrderQuotationRecordBar-->
<script type="text/html" id="inquiryOrderQuotationRecordBar">

    {{# if(!d.whetherFinal){  }}
    <a class="layui-btn layui-btn-xs" lay-event="details">修改</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="final">设为终版</a>
    {{# }else{ }}
    <a class="layui-btn layui-btn-xs" lay-event="details">详情</a>
    {{# } }}

</script>

<!--订单物料列表 报价记录  详情-->
<!--inquiryOrderQuotationRecordDetails-->
<script type="text/html" id="inquiryOrderQuotationRecordDetailsForm">
    <form lay-filter="inquiryOrderQuotationRecordDetailsForm" class="layui-form model-form inquiryOrderBox"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
            <div class="layui-form-item layui-row">
                <input name="id" type="hidden"/>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户名称:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">客户联系人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">联系人电话:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="customerContactsPhone" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">交货时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="deliveryTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属渠道:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="channelName" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">订单录入人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="orderCreatorName" readonly>
                    </div>
                </div>
                <!--<div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">所属部门:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="departmentName" readonly>
                    </div>
                </div>-->
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">提交时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="createTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价截止时间:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="offerEndTime" readonly>
                    </div>
                </div>
                <div class="layui-inline layui-col-md3">
                    <label class="layui-form-label">报价受理人:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" name="checkerName" readonly>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="inquiryOrderQuotationRecordDetailsTable"
                       lay-filter="inquiryOrderQuotationRecordDetailsTable"></table>
            </div>

        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="inquiryOrderQuotationRecordDetailsSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--合同-->
<!--inquiryOrderContract-->
<script type="text/html" id="inquiryOrderContractForm">
    <form lay-filter="inquiryOrderContractForm" class="layui-form model-form"
          style="padding: 5px 30px 0 30px;height: calc(100% - 5px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 75px); padding-top: 20px;overflow: auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <button class="layui-btn color-reseda" id="contractBtnAdd" type="button">添加合同</button>
                </div>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="inquiryOrderContractFormTable"
                       lay-filter="inquiryOrderContractFormTable"></table>
            </div>

        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>
</script>

<!-- 合同表格操作列 -->
<script type="text/html" id="contractTableBar">
    <a class="layui-btn layui-btn-xs" lay-event="view">详情</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="changeRecord">变更记录</a>
</script>

<script type="text/html" id="contractTablePreservationBar">
    <a class="layui-btn layui-btn-xs" lay-event="preservation">保存</a>
</script>

<!--合同附件-->
<script type="text/html" id="viewAttachmentBar">
    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="viewAttachment">查看附件</a>
</script>

<!-- 查看附件 -->
<script type="text/html" id="viewAttachmentHtml">
    <div id="example1" style="height: 100%;"></div>
</script>

<!-- 添加合同弹窗 -->
<script type="text/html" id="contractForm">
    <form lay-filter="contractForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>合同主体类型</label>
            <div class="layui-input-block">
                <select name="type" disabled></select>
            </div>
        </div>
        <div class="layui-form-item" id="PID">
            <label class="layui-form-label"><span style="color: red">*</span>合同分类</label>
            <input name="contractCategoryId" type="hidden" lay-verify="contractCategoryId"/>
            <div class="layui-input-block" id="selectContractCategory">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>签约主体名称</label>
            <div class="layui-input-block">
                <select name="subjectId" lay-filter="getSubject" lay-verify="required" disabled></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>合同名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入合同名称" type="text" class="layui-input" maxlength="200"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>合同编号</label>
            <div class="layui-input-block">
                <input name="code" placeholder="请输入合同编号" type="text" class="layui-input" maxlength="200"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>客户签约人</label>
            <div class="layui-input-block">
                <select name="contactsId" lay-verify="required" required lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>我方签约人</label>
            <div class="layui-input-block">
                <select name="contractor" lay-verify="required" required lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>信息审批人</label>
            <div class="layui-input-block">
                <select name="approver" lay-verify="required" required lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>签约金额</label>
            <div class="layui-input-block">
                <input name="amount" placeholder="请输入签约金额" type="text" class="layui-input" lay-verify="required|decimal"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>上传附件</label>
            <div class="layui-input-block">
                <div id="addDevicePicBtn" class="layui-btn" style="float: left;margin-left: 3px"><i class="layui-icon">&#xe681;</i>上传PDF文件
                </div>
                <div id="addHeaderImg" class="companyFormPhotos"></div>
                <input name="attachment" id="attachment" type="hidden" class="layui-input" lay-verify="attachment"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入备注" maxlength="200" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="contractFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 合同详情 -->
<script type="text/html" id="contractView">
    <form lay-filter="inquiryOrderContractForm" class="layui-form model-form"
          style="padding: 0px 20px;height: calc(100% - 10px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 50px);overflow: visible">
            <div class="layui-form-item">
                <div>
                    <table class="layui-table">
                        <thead>
                        <tr>
                            <th style="width: 35%;">合同信息</th>
                            <th>合同PDF预览内容</th>
                        </tr>
                        </thead>
                        <tbody>
                        <tr>
                            <td id="contractInfo">

                            </td>
                            <td>
                                <div id="attachmentName" style="margin-bottom: 10px; font-size: 16px;">合同附件：</div>
                                <div id="exampleView" style="height: 500px;"></div>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>

</script>

<!-- 合同信息 -->
<script type="text/html" id="contractInfoHtml">
    <div class="info_row">客户名称：{{d.companyName}}</div>
    <div class="info_row">合同名称：{{d.name}}</div>
    <div class="info_row">合同编号：{{d.code}}</div>
    <div class="info_row">客户签约人：{{d.contactName}}</div>
    <div class="info_row" id="contractorName">我方签约人：{{d.contractorName}}</div>
    <div class="info_row">签约时间：{{d.signingTime ? d.signingTime : ""}}</div>
    <div class="info_row">交货时间：{{d.deliveryTime ? d.deliveryTime : ""}}</div>
    <div class="info_row">备注信息：{{d.remark}}</div>
    <div class="info_row">合同金额：{{d.amount}}</div>
    <div style="overflow: hidden; padding: 5px 0;">
        <div style="float: left;">合同附件：</div>
        {{# var attachment = "";
        if(d.attachment){
        attachment = d.attachment.substring(d.attachment.lastIndexOf("/")+1);
        }
        var time = timeStamp2String(d.createTime);
        }}
        <div class="attachments">
            <div onclick="previewFile('{{attachment}}', '{{d.attachment}}');">
                <img src="../../../admin/assets/images/attachmentsIcon/pdf.png">
                <span class="file-a">{{attachment}}</span>
                <span class="file-a">{{time}}</span>
            </div>
        </div>
    </div>
    <div class="info_row">合同存放地点：{{d.address ? d.address : ""}}</div>
    <div class="info_row" id="keeperName">合同保管员：{{d.keeperName ? d.keeperName : ""}}</div>
    <!--<div class="info_row">合同状态：{{d.statusDesc}}</div>-->
    <div class="info_row" id="approverName">信息审批人：{{d.approverName ? d.approverName : ""}}</div>
    <div class="info_row">审核结果：{{d.statusDesc ? d.statusDesc : ""}}</div>
    <div class="info_row">审核意见备注：{{d.auditOpinion ? d.auditOpinion : ""}}</div>
</script>

<!-- 合同变更记录 -->
<script type="text/html" id="contractChangeRecord">
    <form lay-filter="inquiryOrderContractForm" class="layui-form model-form"
          style="padding: 0px 20px;height: calc(100% - 0px);overflow: hidden;">
        <div class="open-details-box" style="height: calc(100% - 70px);overflow: visible; padding-top: 20px">
            <div class="layui-form-item">
                <button id="contractChangeRecordBtnAdd" class="layui-btn icon-btn color-reseda">添加合同变更记录</button>
            </div>
            <div class="layui-form-item">
                <table class="layui-table" id="contractChangeRecordTable"
                       lay-filter="contractChangeRecordTable"></table>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
        </div>
    </form>

</script>

<!-- 合同变更记录 表格操作列 -->
<script type="text/html" id="contractChangeRecordTableBar">
    {{# if(d.status == 'stayAudit' || d.status == 'fail'){ }}
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
    {{# } }}
    <a class="layui-btn layui-btn-xs" lay-event="view">详情</a>
    {{# if(d.status == 'stayAudit'){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="audit">审核</a>
    {{# } }}
    {{# if(d.status == 'success'){ }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="final">终版</a>
    {{# } }}
</script>

<!--添加 修改 合同变更记录-->
<script type="text/html" id="contractChangeRecordForm">
    <form lay-filter="contractChangeRecordForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item" id="PIDChangeRecord">
            <label class="layui-form-label"><span style="color: red">*</span>合同分类</label>
            <input name="contractCategoryId" type="hidden" lay-verify="contractCategoryId"/>
            <div class="layui-input-block" id="selectContractCategoryChangeRecord"></div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>签约主体名称</label>
            <div class="layui-input-block">
                <input name="companyName" type="text" class="layui-input" style="border: 0;" readonly/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>合同名称</label>
            <div class="layui-input-block">
                <input name="name" placeholder="请输入合同名称" type="text" class="layui-input" maxlength="200"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>合同编号</label>
            <div class="layui-input-block">
                <input name="code" placeholder="请输入合同编号" type="text" class="layui-input" readonly maxlength="200"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>客户签约人</label>
            <div class="layui-input-block">
                <select name="contactsId" lay-verify="required" required lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>我方签约人</label>
            <div class="layui-input-block">
                <select name="contractor" lay-verify="required" required lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>签约时间</label>
            <div class="layui-input-block">
                <input name="signingTime" id="signingTime" placeholder="请选择签约时间" type="text" class="layui-input"
                       readonly lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>信息审批人</label>
            <div class="layui-input-block">
                <select name="approver" lay-verify="required" required lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">备注信息</label>
            <div class="layui-input-block">
                <textarea name="remark" placeholder="请输入备注信息" maxlength="200" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>上传附件</label>
            <div class="layui-input-block">
                <div id="addDevicePicBtnChangeRecord" class="layui-btn" style="float: left;margin-left: 3px"><i
                        class="layui-icon">&#xe681;</i>上传PDF文件
                </div>
                <div id="addHeaderImgChangeRecord" class="companyFormPhotos"></div>
                <input name="attachment" id="attachmentChangeRecord" type="hidden" class="layui-input"
                       lay-verify="attachment"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>签约金额</label>
            <div class="layui-input-block">
                <input name="amount" placeholder="请输入签约金额" type="text" class="layui-input" lay-verify="required|decimal"
                       required/>
            </div>
        </div>
        <div class="layui-form-item" style="display: none">
            <label class="layui-form-label"><span style="color: red">*</span>是否最终版</label>
            <div class="layui-input-block">
                <input name="isFinal" type="checkbox" lay-skin="switch" lay-filter="isFinal" lay-text="是|否"/>
            </div>
        </div>
        <div id="content" style="display: none;">
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>交货时间</label>
                <div class="layui-input-block">
                    <input name="deliveryTime" id="deliveryTimeChangeRecord" placeholder="请选择交货时间" type="text"
                           class="layui-input" readonly/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>合同存放地点</label>
                <div class="layui-input-block">
                    <input name="address" placeholder="请输入合同存放地点" type="text" class="layui-input"/>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label"><span style="color: red">*</span>合同保管员</label>
                <div class="layui-input-block">
                    <select name="keeper"></select>
                </div>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="contractChangeRecordFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!-- 合同审核界面 -->
<script type="text/html" id="contractAuditForm">
    <form lay-filter="contractAuditForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label">审核意见</label>
            <div class="layui-input-block">
                <textarea name="auditOpinion" placeholder="请输入审核意见" maxlength="200" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn" data-status="success" lay-filter="contractAuditFormSubmit" lay-submit>审核通过
            </button>
            <button class="layui-btn layui-btn-danger" data-status="fail" lay-filter="contractAuditFormSubmit"
                    lay-submit>审核不通过
            </button>
        </div>
    </form>
    <div style="padding: 20px;">
        <table class="layui-table">
            <thead>
            <tr>
                <th style="width: 35%;">合同信息</th>
                <th>合同PDF预览内容</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td id="contractInfoAudit">

                </td>
                <td>
                    <div id="attachmentNameAudit" style="margin-bottom: 10px; font-size: 16px;">合同附件：</div>
                    <div id="example1Audit" style="height: 500px;"></div>
                </td>
            </tr>
            </tbody>
        </table>
    </div>
</script>

<!-- 终版弹窗 -->
<script type="text/html" id="contractFinalForm">
    <form lay-filter="contractFinalForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>交货时间</label>
            <div class="layui-input-block">
                <input name="deliveryTime" id="deliveryTimeFina" placeholder="请选择交货时间" type="text" class="layui-input"
                       readonly lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>合同存放地点</label>
            <div class="layui-input-block">
                <input name="address" placeholder="请输入合同存放地点" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span style="color: red">*</span>合同保管员</label>
            <div class="layui-input-block">
                <select name="keeper" lay-verify="required" required lay-search></select>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="contractFinalFormSubmit" lay-submit>确认终版</button>
        </div>
    </form>
</script>


<!-- js部分 -->

<script type="text/javascript" src="../../../admin/assets/js/pdfobject.min.js"></script>
<script type="text/javascript" src="../../../admin/assets/js/jsencrypt.min.js"></script>

<script>

    //在Jquery里格式化Date日期时间数据
    function timeStamp2String(time) {
        var datetime = new Date(time);
        var year = datetime.getFullYear();
        var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
        var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
        var hour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
        var minute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
        var second = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
        // return year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second;
        return year + "年" + month + "月" + date + "日";
    }

    layui.use(['layer', 'form', 'table', 'admin', 'laydate', 'upload', 'laytpl'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        let laydate = layui.laydate;
        let laytpl = layui.laytpl;
        let InquiryOrderDetailsFormData = {};


        form.render('select');
        // 渲染表格
        let insTb = table.render({
            elem: '#orderTable',
            // url: config.base + 'enterprise/sell/admin/order/list',
            url: config.base + 'enterprise/sell/admin/proffOrder/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号'}
                , {field: 'code', sort: true, title: '订单编号'}
                , {field: 'orderSourceDesc', sort: true, title: '订单来源'}
                , {field: 'customerName', sort: true, title: '客户名称'}
                , {field: 'orderTypeDesc', sort: true, title: '订单类型'}
                , {field: 'proQuantity', sort: true, title: '物料数量'}
                , {field: 'amount', sort: true, title: '订单总金额'}
                , {field: 'statusDesc', sort: true, title: '订单状态'}
                , {field: 'creatorName', sort: true, title: '添加人'}
                , {field: 'createTime', sort: true, title: '添加时间'}
                , {align: 'left', toolbar: '#orderTableBar', title: '操作', width: 400}
            ]],
            done: function (res, curr, count) {
            }
        });

        // 工具条点击事件
        table.on('tool(orderTable)', function (obj) {
            let data = obj.data;
            if (obj.event === 'edit') { //修改
                showInquiryOrderInformation(data);
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            } else if (obj.event === 'confirmSubmission') {
                doConfirm(data, 1)
            } else if (obj.event === 'details') {
                InquiryOrderDetailsFormData = '';
                InquiryOrderDetailsFormData = data;
                showInquiryOrderDetailsForm(data, 'details', '订单详情');
            } else if (obj.event === 'acceptance') { // 受理
                InquiryOrderDetailsFormData = '';
                InquiryOrderDetailsFormData = data;
                showInquiryOrderDetailsForm(data, 'acceptance', '订单物料列表');
            } else if (obj.event === 'review') { // 评审
                InquiryOrderDetailsFormData = '';
                InquiryOrderDetailsFormData = data;
                showInquiryOrderDetailsForm(data, 'review', '订单评审');
            } else if (obj.event === 'closure') { // 结案
                doConfirm(data, 7)
            } else if (obj.event === 'offer') { //报价
                InquiryOrderDetailsFormData = '';
                InquiryOrderDetailsFormData = data;
                showInquiryOrderOfferForm(data)
            } else if (obj.event === 'quotationRecord') { // 报价记录
                InquiryOrderDetailsFormData = '';
                InquiryOrderDetailsFormData = data;
                showInquiryOrderQuotationRecordForm(data)
            } else if (obj.event === 'contract') { // 合同
                InquiryOrderDetailsFormData = '';
                InquiryOrderDetailsFormData = data;
                showInquiryOrderContractForm(data)
            }
        });

        //监听排序
        table.on('sort(orderTable)', function (obj) {
            table.reload('orderTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            var field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
            return false;
        });

        // 添加按钮点击事件
        $('#inquiryOrderInformationBtnAdd').click(function () {
            showInquiryOrderInformation();
            return false;
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '900px',
                offset: '65px',
                title: data ? '修改订单' : '添加订单',
                content: $('#orderForm').html(),
                success: function () {
                    if (data) {
                        var option = $("form select[name='orderSource']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.orderSource == item.text) {
                                data.orderSource = item.value;
                            }
                        });
                    }

                    if (data) {
                        var option = $("form select[name='orderType']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.orderType == item.text) {
                                data.orderType = item.value;
                            }
                        });
                    }

                    if (data) {
                        var option = $("form select[name='status']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.status == item.text) {
                                data.status = item.value;
                            }
                        });
                    }

                    form.val('orderForm', data);
                    // 表单提交事件
                    form.on('submit(orderFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'enterprise/sell/admin/order/update' : 'enterprise/sell/admin/order/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('orderTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/sell/admin/order/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 导出excel
        $('#orderBtnExport').click(function () {
            var checkRows = table.checkStatus('orderTable');
            if (checkRows.data.length == 0) {
                layer.msg('请选择要导出的数据', {icon: 2});
            } else {
                table.exportFile(insTb.config.id, checkRows.data, 'xls');
            }
        });

        // 添加询价订单信息
        function showInquiryOrderInformation(data) {
            admin.open({
                type: 1,
                area: ['1500px', '800px'],
                offset: '65px',
                title: data ? '修改订单' : '添加订单',
                content: $('#inquiryOrderInformationForm').html(),
                success: function () {

                    let inquiryOrderInformationData = [],// table数据;
                        proTypeIdData = [],// 物料类型数据
                        proUnitIdData = [], // 物料单位数据
                        deleteIds = [], // 被删除的id
                        contractId = {};// 合同请求参数
                    form.render('select');
                    laydate.render({
                        elem: '#deliveryTime',
                        type: 'datetime'
                    });
                    laydate.render({
                        elem: '#offerEndTime',
                        type: 'datetime'

                    });

                    // 客户名称
                    admin.reqSync('enterprise/sell/admin/order/getCustomers', {}, function (res) {
                        if (res.code == 200) {
                            loadSelectHtml(res.data, "客户名称", "customerId", 1, 'inquiryOrderInformationForm');
                        }
                    }, 'GET');
                    // 客户名称下拉事件
                    form.on('select(customerId)', function (data) {
                        $("form[lay-filter='inquiryOrderInformationForm'] input[name='telephone']").val("");
                        getSelCustomerIdData(data.value);

                        // 请求合同
                        getSelContractIdData(data);
                    });

                    // 请求合同
                    function getSelContractIdData(_data) {
                        if (_data.value) {
                            $('#contractIdBox').show({duration: 300});
                            contractId.customerName = _data.elem[_data.elem.selectedIndex].text;
                            contractId.customerId = _data.value;
                            admin.reqSync('enterprise/sell/admin/customerContract/list', {'subjectId': _data.value}, function (res) {
                                if (res.code == 200) {
                                    loadSelectHtml(res.data, "选择合同", "contractId", 3, 'inquiryOrderInformationForm');
                                }
                            }, 'GET');
                        } else {
                            $('#contractIdBox').hide({duration: 300});
                            contractId.customerName = "";
                            contractId.customerId = "";
                            loadSelectHtml([], "选择合同", "contractId", 3, 'inquiryOrderInformationForm');
                        }
                    }

                    //请求客户联系人
                    function getSelCustomerIdData(_data) {
                        if (_data) {
                            admin.reqSync('enterprise/sell/admin/contactInfo/list', {'selCustomerId': _data}, function (res) {
                                if (res.code == 200) {
                                    loadSelectHtml(res.data, "客户联系人", "customerContactsId", 2, 'inquiryOrderInformationForm');
                                }
                            }, 'GET');
                        } else {
                            loadSelectHtml([], "客户联系人", "customerContactsId", 2, 'inquiryOrderInformationForm');
                        }
                    }

                    form.on('select(customerContactsId)', function (data) {
                        showTelephone(data)
                    });

                    function showTelephone(_data) {
                        if (_data.value) {
                            $("form[lay-filter='inquiryOrderInformationForm'] input[name='customerContactsPhone']").val($(_data.elem).find("option:selected").attr("phone"))
                        } else {
                            $("form[lay-filter='inquiryOrderInformationForm'] input[name='customerContactsPhone']").val("")
                        }
                    }

                    //所属渠道
                    admin.reqSync('enterprise/sell/admin/agent/list', {}, function (res) {
                        if (res.code == 200) {
                            loadSelectHtml(res.data, "非渠道订单", "channelId", 3, 'inquiryOrderInformationForm');
                        }
                    }, 'GET');

                    //询价审核人
                    admin.reqSync('user/admin/user/list', {limit: 9999}, function (res) {
                        if (res.code == 200) {
                            loadSelectHtml(res.data, "询价审核人", "checkerId", 4, 'inquiryOrderInformationForm');
                        }
                    }, 'GET');
                    form.on('select(checkerId)', function (data) {
                        showCheckerName(data);
                    });

                    function showCheckerName(_data) {
                        if (_data) {
                            $("form[lay-filter='inquiryOrderInformationForm'] input[name='checkerName']").val(_data.elem[_data.elem.selectedIndex].text)
                        } else {
                            $("form[lay-filter='inquiryOrderInformationForm'] input[name='checkerName']").val("")
                        }
                    }

                    // 物料类型
                    admin.reqSync('enterprise/product/admin/productType/list', {}, function (res) {
                        if (res.code == 200) {
                            proTypeIdData = res.data;
                        }
                    }, 'GET');

                    // 物料单位
                    admin.reqSync('enterprise/product/admin/productUnit/list', {}, function (res) {
                        if (res.code == 200) {
                            proUnitIdData = res.data;
                        }
                    }, 'GET');


                    //添加客户
                    $('#addCustomerBtn').click(function () {
                        addCustomer();
                        return false;
                    });

                    // 添加合同
                    $('#contractIdAddBtn').click(function () {
                        showContractForm(contractId, 'add', true);
                        // showContractForm(数据[必须包含customerName,customerId],  类型[add:添加,edit:修改], 刷新合同下拉框)
                        return false;
                    });

                    if (data) {
                        getSelCustomerIdData(data.customerId);
                        let dataObj = JSON.parse(JSON.stringify(data));
                        dataObj.orderProList.forEach((item, index) => {
                            item.proTypeIdData = proTypeIdData;
                            item.proUnitIdData = proUnitIdData;
                            inquiryOrderInformationData.push(item)
                        });
                        form.val('inquiryOrderInformationForm', data);
                    }
                    let inquiryOrderInformationTb = table.render({
                        elem: '#inquiryOrderInformationTable',
                        toolbar: '#inquiryOrderInformationFormToolbar',
                        defaultToolbar: false,
                        data: inquiryOrderInformationData,
                        page: false,
                        limit: Number.MAX_VALUE,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {
                                field: 'proTypeId', title: '物料类型', templet: d => {
                                    let selectHTML = '';
                                    selectHTML += '<select name="proTypeId" lay-filter="proTypeId" lay-verify="required" lay-search="">';
                                    selectHTML += '<option value="">物料类型</option>';
                                    d.proTypeIdData.forEach(item => {
                                        if (d.proTypeId == item.id) {
                                            selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                        } else {
                                            selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';

                                        }
                                    });
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'customerSkuItem',
                                title: '客户SKU料号',
                                templet: d => '<input type="text" name="customerSkuItem" class="layui-input" lay-verify="required" value="' + d.customerSkuItem + '"> <input type="hidden" name="objDataListId"  value="' + d.id + '">'
                            }
                            , {
                                field: 'customerSkuName',
                                title: '客户物料名称',
                                templet: d => '<input type="text" name="customerSkuName" class="layui-input" lay-verify="required" value="' + d.customerSkuName + '">'
                            }
                            , {
                                field: 'customerSpecCode',
                                title: '客户规格码',
                                templet: d => '<input type="text" name="customerSpecCode" class="layui-input" lay-verify="required" value="' + d.customerSpecCode + '">'
                            }
                            , {
                                field: 'attachments', title: '附件', width: 80, align: 'center', templet: d => {
                                    let btnHTML = '<a class="layui-btn layui-btn-xs" lay-event="uploadAttachment">上传附件</a>';
                                    d.orderProEnclosureList.forEach((item, index) => {
                                        btnHTML += '<br />';
                                        btnHTML += '<a class="layui-btn layui-btn-xs layui-btn-warm" href="' + item.fileUrl + '" target="_blank" title="' + item.fileName + '">查看附件</a>';
                                    });
                                    return btnHTML;
                                }
                            }
                            , {
                                field: 'proUnitId', title: '单位', templet: d => {
                                    let selectHTML = '';
                                    selectHTML += '<select name="proUnitId" lay-filter="proUnitId" lay-verify="required" lay-search="">';
                                    selectHTML += '<option value="">请选择单位</option>';
                                    d.proUnitIdData.forEach(item => {
                                        if (d.proUnitId == item.id) {
                                            selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                        } else {
                                            selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';

                                        }
                                    });
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'quantity',
                                title: '需求数量',
                                templet: d => '<input type="text" name="quantity" class="layui-input" lay-verify="number" value="' + d.quantity + '">'
                            }
                            , {
                                field: 'proRemark',
                                title: '说明',
                                templet: d => '<input type="text" name="proRemark" class="layui-input"  value="' + d.proRemark + '">'
                            }
                            , {
                                field: 'whetherPack', title: '是否需要包装', templet: d => {
                                    let selectHTML = '';
                                    selectHTML += '<select name="whetherPack" lay-filter="whetherPack">';
                                    selectHTML += `<option value="0" ${d.whetherPack == 0 ? 'selected=""' : ''}>需要</option>`;
                                    selectHTML += `<option value="1" ${d.whetherPack == 1 ? 'selected=""' : ''}>不需要</option>`;
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'packExplain',
                                title: '包装说明',
                                templet: d => '<input type="text" name="packExplain" class="layui-input" value="' + d.packExplain + '">'
                            }
                            , {align: 'center', toolbar: '#inquiryOrderInformationFormBar', title: '操作'}
                        ]],
                        done: function (res, curr, count) {
                            for (let i = 0; i < count; i++) {
                                upload.render({
                                    elem: $('div[lay-id="inquiryOrderInformationTable"]').find('[lay-event="uploadAttachment"]').eq(i)
                                    , url: config.upload_url + 'uploadFile' //上传接口
                                    , data: {}
                                    , accept: 'file'
                                    , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx|apk'
                                    , headers: {Authorization: 'Bearer ' + config.getToken()}
                                    , done: function (res) {
                                        if (res.code == 200) {
                                            layer.msg(res.msg || "上传成功", {icon: 1});
                                            let imgObj = {
                                                fileUrl: res.data.url,
                                                fileName: res.data.fileName
                                            };
                                            inquiryOrderInformationData[this.elem.parents('tr').index()].orderProEnclosureList.push(imgObj);
                                            table.reload('inquiryOrderInformationTable', {data: inquiryOrderInformationData});
                                        } else if (res.code == 502) {
                                            return location.replace('admin/login.html');
                                        } else {
                                            layer.msg(res.msg || "上传失败", {icon: 2});
                                        }
                                    }
                                });
                            }
                            form.render('select');
                        }
                    });

                    // 头工具栏事件
                    table.on('toolbar(inquiryOrderInformationTable)', function (obj) {
                        if (obj.event === 'addProduct') { //addItemBtn 添加物料
                            let inquiryOrderInformationDataObj = {
                                proTypeId: '',
                                customerSkuItem: '',
                                customerSkuName: '',
                                customerSpecCode: '',
                                attachments: '',
                                proUnitId: '',
                                proUnitIdData,
                                proTypeIdData,
                                quantity: '',
                                proRemark: '',
                                whetherPack: 0,
                                packExplain: '',
                                orderProEnclosureList: []
                            };
                            inquiryOrderInformationData.push(inquiryOrderInformationDataObj);
                            table.reload('inquiryOrderInformationTable', {data: inquiryOrderInformationData});
                        }
                    });


                    // 工具条点击事件
                    table.on('tool(inquiryOrderInformationTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'delete') { //删除
                            if (data.id) {
                                deleteIds.push(data.id)
                            }
                            inquiryOrderInformationData.splice(obj.tr.index(), 1);
                            table.reload('inquiryOrderInformationTable', {data: inquiryOrderInformationData});
                        }
                    });

                    form.on("select", function (data) {
                        if ($(data.elem).attr('name') == 'proUnitId') {
                            inquiryOrderInformationData[$(data.elem).parents('tr').index()].proUnitId = data.value;
                        } else if ($(data.elem).attr('name') == 'proTypeId') {
                            inquiryOrderInformationData[$(data.elem).parents('tr').index()].proTypeId = data.value;
                        } else if ($(data.elem).attr('name') == 'whetherPack') {
                            inquiryOrderInformationData[$(data.elem).parents('tr').index()].whetherPack = data.value;
                        }
                    });

                    $("body").delegate("[lay-id='inquiryOrderInformationTable'] input[name='customerSkuItem']", "change", function () {
                        if (inquiryOrderInformationData[$(this).parents('tr').index()]) {
                            inquiryOrderInformationData[$(this).parents('tr').index()].customerSkuItem = $(this).val().trim();
                        }
                    });
                    $("body").delegate("[lay-id='inquiryOrderInformationTable'] input[name='customerSkuName']", "change", function () {
                        if (inquiryOrderInformationData[$(this).parents('tr').index()]) {
                            inquiryOrderInformationData[$(this).parents('tr').index()].customerSkuName = $(this).val().trim();
                        }
                    });
                    $("body").delegate("[lay-id='inquiryOrderInformationTable'] input[name='customerSpecCode']", "change", function () {
                        if (inquiryOrderInformationData[$(this).parents('tr').index()]) {
                            inquiryOrderInformationData[$(this).parents('tr').index()].customerSpecCode = $(this).val().trim();
                        }
                    });
                    $("body").delegate("[lay-id='inquiryOrderInformationTable'] input[name='quantity']", "change", function () {
                        if (inquiryOrderInformationData[$(this).parents('tr').index()]) {
                            inquiryOrderInformationData[$(this).parents('tr').index()].quantity = $(this).val().trim();
                        }
                    });
                    $("body").delegate("[lay-id='inquiryOrderInformationTable'] input[name='proRemark']", "change", function () {
                        if (inquiryOrderInformationData[$(this).parents('tr').index()]) {
                            inquiryOrderInformationData[$(this).parents('tr').index()].proRemark = $(this).val().trim();
                        }
                    });
                    $("body").delegate("[lay-id='inquiryOrderInformationTable'] input[name='packExplain']", "change", function () {
                        if (inquiryOrderInformationData[$(this).parents('tr').index()]) {
                            inquiryOrderInformationData[$(this).parents('tr').index()].packExplain = $(this).val().trim();
                        }
                    });

                    //保存
                    form.on('submit(inquiryOrderInformationSubmit)', function (d) {
                        let objData = {}, objDataList = [];
                        layer.load(2);
                        new Promise((resolve, reject) => {
                            inquiryOrderInformationData.forEach((item, index) => {
                                objDataList[index] = {};
                                objDataList[index].proTypeId = item.proTypeId;
                                objDataList[index].customerSkuItem = item.customerSkuItem;
                                objDataList[index].customerSkuName = item.customerSkuName;
                                objDataList[index].customerSpecCode = item.customerSpecCode;
                                objDataList[index].orderProEnclosureList = item.orderProEnclosureList;
                                objDataList[index].proUnitId = item.proUnitId;
                                objDataList[index].quantity = item.quantity;
                                objDataList[index].proRemark = item.proRemark;
                                objDataList[index].whetherPack = item.whetherPack == 0 ? 'true' : 'false';
                                objDataList[index].packExplain = item.packExplain;
                                item.id ? objDataList[index].id = item.id : '';
                            });
                            resolve(objDataList);
                        }).then(r => {
                            d.field.id ? objData.id = d.field.id : '';
                            objData.customerId = d.field.customerId;
                            objData.checkerName = d.field.checkerName;
                            objData.checkerId = d.field.checkerId;
                            objData.customerContactsId = d.field.customerContactsId;
                            objData.channelId = d.field.channelId;
                            objData.deliveryTime = d.field.deliveryTime;
                            objData.offerEndTime = d.field.offerEndTime;
                            objData.remark = d.field.remark;
                            objData.orderType = d.field.orderType;
                            objData.customerContactsPhone = d.field.customerContactsPhone;
                            objData.orderSource = d.field.orderSource;
                            objData.contractId = d.field.contractId;
                            objData.orderProList = r;
                        }).then(() => {
                            admin.req(data ? 'enterprise/sell/admin/order/update' : 'enterprise/sell/admin/proffOrder/add', JSON.stringify(objData), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('orderTable');
                                    layer.closeAll('page');
                                    if (deleteIds.length > 0) {
                                        showInquiryOrderInformationListDoDelete(deleteIds.toString())
                                    }
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, data ? 'PUT' : 'POST', true, 'application/json; charset=utf-8');
                        });
                        return false;
                    });
                }
            })
        }

        // 删除
        function showInquiryOrderInformationListDoDelete(obj) {
            admin.req('enterprise/sell/admin/orderPro/delBatch?ids=' + obj, {}, function (res) {
            }, 'DELETE');
        }

        // 渲染下拉框数据
        function loadSelectHtml(data, tips, htmltarget, type, formName) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                if (type === 1) {
                    html += `<option value='${data[i].id}'>${data[i].customerName}</option>`;
                } else if (type === 2) {
                    html += `<option value='${data[i].id}' phone='${data[i].telephone}'>${data[i].name}</option>`;
                } else if (type === 3) {
                    html += `<option value='${data[i].id}'>${data[i].name}</option>`;
                } else if (type === 4) {
                    html += `<option value='${data[i].id}'>${data[i].username}</option>`;
                }
            }

            $("form[lay-filter='" + formName + "']  select[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        // 上传图片
        function uploadImg(_elem, pathId, inputId) {
            upload.render({
                elem: '#' + _elem
                , url: config.upload_url + 'uploadFile'
                , data: {}
                , accept: 'file'
                , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                , headers: {Authorization: 'Bearer ' + config.getToken()}
                , done: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg || "上传成功", {icon: 1});
                        let imagUrl = res.data.url;
                        $('#' + pathId).html('<img src="' + imagUrl + '" style="height: 35px;"/>');
                        $('#' + inputId).val(imagUrl);
                    } else if (res.code == 502) {
                        return location.replace('admin/login.html');
                    } else {
                        layer.msg(res.msg || "上传失败", {icon: 2});
                    }
                }
            });
        }

        //获取审批人和业务员
        function getUsers() {
            admin.req('user/admin/user/list', {limit: 9999}, function (res) {
                if (res.code == 200) {
                    var html = '<option value="">请选择</option>';
                    for (var k = 0; k < res.data.length; k++) {
                        html += '<option value="' + res.data[k].id + '">' + res.data[k].username + '</option>';
                    }
                    $("form select[name='approver']").html(html);
                    $("form select[name='salesmanId']").html(html);
                    form.render('select');
                } else {
                    layer.msg('获取审批人失败', {icon: 2, time: 1000});
                }
            }, 'GET');
        }

        //获取代理商
        function getAgentInfo() {
            admin.req('enterprise/sell/admin/agent/list?status=1', {limit: 9999}, function (res) {
                if (res.code == 200) {
                    var html = '<option value="">请选择</option>';
                    for (var k = 0; k < res.data.length; k++) {
                        html += '<option value="' + res.data[k].id + '">' + res.data[k].name + '</option>';
                    }
                    $("form select[name='selAgtId']").html(html);
                    form.render('select');
                } else {
                    layer.msg('获取代理商失败', {icon: 2, time: 1000});
                }
            }, 'GET');
        }

        //添加客户
        function addCustomer() {
            let addCustomerPage = admin.open({
                type: 1,
                area: ['1400px', '800px'],
                offset: '85px',
                title: '添加客户信息',
                content: $('#customersInfoForm').html(),
                success: function () {
                    getUsers();//获取审批人和业务员
                    getAgentInfo();//获取代理商
                    // 获取省区域信息

                    function loadSelectHtmlCustomer(data, tips, htmltarget, name) {
                        let html = ' <option value>' + tips + '</option>';
                        if (!data || data == null) {
                            return;
                        }
                        for (let i = 0; i < data.length; i++) {
                            html += `<option value='${data[i].id}'>${data[i][name]}</option>`;
                        }
                        $("[name='" + htmltarget + "']").html(html);
                        form.render('select');
                    }


                    admin.req('enterprise/area/getProvinceList', {}, function (res) {
                        if (200 == res.code) {
                            loadSelectHtmlCustomer(res.data, "请选择省份", "province", "name");
                        }
                    }, 'POST', true);
                    var selectArea = function (city) {
                        admin.req('enterprise/area/getAreaList?parentId=' + city, {}, function (res) {
                            layer.closeAll('loading');
                            if (200 == res.code) {
                                loadSelectHtmlCustomer(res.data, "请选择区/县", "area", "name");
                            }
                        }, 'POST');
                    }
                    var selectCity = function (province) {
                        admin.req('enterprise/area/getCityList?parentId=' + province, {}, function (res) {
                            layer.closeAll('loading');
                            if (200 == res.code) {
                                loadSelectHtmlCustomer(res.data, "请选择市", "city", "name");
                            }
                        }, 'POST');
                    }
                    form.on('select(province)', function (data) {
                        $("#city").empty();
                        $('#area').empty();
                        // 获取市区域信息
                        if (data.value != '') {
                            selectCity(data.value);
                        }
                    });
                    form.on('select(city)', function (data) {
                        $('#area').empty();
                        // 获取区县区域信息
                        if (data.value != '') {
                            selectArea(data.value);
                        }
                    });
                    //上传名片
                    uploadImg("btnUpload15", "btnUpload15_path", "btnUpload15_file");
                    $("#customerType").attr("disabled", "disabled");
                    // 表单提交事件
                    form.on('submit(customersInfoFormSubmit)', function (d) {
                        layer.load(2);
                        d.field.customerType = 'Intended';
                        admin.req('enterprise/sell/admin/intendedCustomersInfo/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                layer.close(addCustomerPage);
                                admin.req('enterprise/sell/admin/order/getCustomers', {}, function (res) {
                                    if (res.code == 200) {
                                        loadSelectHtml(res.data, "客户名称", "customerId", 1, 'inquiryOrderInformationForm');
                                    }
                                }, 'GET');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'POST');
                        return false;
                    });
                }
            });
        }

        // 公共方法修改订单数据
        function doConfirm(data, _type) {
            layer.confirm('确定要提交吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/sell/admin/order/submit', {id: data.id, type: _type}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        layer.closeAll('page');
                        table.reload('orderTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'POST');
            });
        }

        // 询价订单详情
        function showInquiryOrderDetailsForm(data, _type, _title) {
            admin.open({
                type: 1,
                area: ['1500px', '800px'],
                offset: '65px',
                title: _title ? _title : '订单详情',
                content: $('#inquiryOrderDetailsForm').html(),
                success: function () {
                    let finalResultType = '4';
                    let colsData = [
                        {type: 'numbers', title: '序号'}
                        , {field: 'customerSkuItem', title: '客户SKU料号'}
                        , {field: 'customerSkuName', title: '物料名称'}
                        , {field: 'customerSpecCode', title: '规格码'}
                        , {
                            field: 'orderProEnclosureList', title: '附件', templet: d => {
                                let orderProEnclosureListHtml = '';
                                d.orderProEnclosureList.forEach((item, index) => {
                                    orderProEnclosureListHtml += '<a href="' + item.fileUrl + '" download="12" target="_blank" class="layui-btn layui-btn-xs layui-btn-warm">查看附件</a></br />'
                                });
                                return orderProEnclosureListHtml;
                            }
                        }
                        , {field: 'proUnitName', title: '单位'}
                        , {field: 'quantity', title: '数量'}
                        , {field: 'proRemark', title: '备注'}
                        , {field: 'statusDesc', title: '状态'}
                    ];

                    if (_type == 'details') {
                        $('button[lay-filter="inquiryOrderDetailsSubmit"]').hide();
                    } else if (_type == 'acceptance') {
                        colsData.push({align: 'center', toolbar: '#inquiryOrderDetailsExamineBar', title: '操作'})
                    } else if (_type = 'review') {
                        colsData.push({align: 'center', toolbar: '#inquiryOrderDetailsReviewBar', title: '操作'})
                    }

                    //   请求所属部门
                    /*admin.reqSync('user/admin/user/getUserInfoByUserId', {userId: data.creator}, res => {
                        if (res.code === 200) {
                            InquiryOrderDetailsFormData.departmentName = res.data.departmentName;
                        }
                    }, 'get');*/

                    form.val('inquiryOrderDetailsForm', InquiryOrderDetailsFormData);

                    let inquiryOrderDetailsTb = table.render({
                        elem: '#inquiryOrderDetailsTable',
                        data: InquiryOrderDetailsFormData.orderProList,
                        page: false,
                        cellMinWidth: 100,
                        cols: [colsData],
                        done: function (res, curr, count) {
                            finalResultType = InquiryOrderDetailsFormData.orderProList.some(item => item.finalResult == "pass") ? '4' : '3';
                            $('button[lay-filter="inquiryOrderDetailsSubmit"]').hide();

                            if (_type == 'acceptance') {
                                if (data.status == 'accept') {
                                    if (res.data.some(item => item.status == "pending")) {
                                        $('button[lay-filter="inquiryOrderDetailsSubmit"]').hide();
                                    } else {
                                        $('button[lay-filter="inquiryOrderDetailsSubmit"]').show();
                                    }
                                } else {
                                    $('button[lay-filter="inquiryOrderDetailsSubmit"]').hide();
                                }

                            } else if (_type == 'review') {
                                if (data.status == 'review') {
                                    if (res.data.some(item => item.finalResult == "unhandled")) {
                                        $('button[lay-filter="inquiryOrderDetailsSubmit"]').hide();
                                    } else {
                                        $('button[lay-filter="inquiryOrderDetailsSubmit"]').show();
                                    }
                                } else {
                                    $('button[lay-filter="inquiryOrderDetailsSubmit"]').hide();

                                }

                            }

                        }
                    });

                    // 工具条点击事件
                    table.on('tool(inquiryOrderDetailsTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'examine') { // 审核
                            showInquiryOrderExamineForm(data, 'examine')
                        } else if (obj.event === 'inquiryOrderDetailsExamineDetails') { // 详情
                            showInquiryOrderExamineForm(data, 'details')
                        } else if (obj.event === 'review') {
                            showInquiryOrderReviewForm(data, 'review')
                        } else if (obj.event === 'reviewDetails') {
                            showInquiryOrderReviewForm(data, 'details')
                        }
                    });


                    if (_type == 'acceptance') {
                        //保存
                        form.on('submit(inquiryOrderDetailsSubmit)', function (d) {
                            doConfirm(InquiryOrderDetailsFormData, 2);
                            return false;
                        });
                    } else if (_type = 'review') {
                        //保存

                        form.on('submit(inquiryOrderDetailsSubmit)', function (d) {
                            doConfirm(InquiryOrderDetailsFormData, finalResultType);
                            return false;
                        });
                    }


                }
            });
        }

        // 询价订单审核
        function showInquiryOrderExamineForm(data, _type) {
            let inquiryOrderExaminePop = admin.open({
                type: 1,
                area: ['1450px', '750px'],
                offset: '75px',
                title: _type == 'examine' ? '订单审核' : '订单详情',
                content: $('#inquiryOrderExamineForm').html(),
                success: function () {
                    let inquiryOrderExamineOrderProReviewTbData = []; // 评审环节本地列表数据
                    let reviewProcessIdData = []; // 评审环节下拉框数据
                    form.val('inquiryOrderExamineForm', InquiryOrderDetailsFormData);
                    let inquiryOrderExamineTb = table.render({
                        elem: '#inquiryOrderExamineTable',
                        data: [data],
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'customerSkuItem', title: '客户SKU料号'}
                            , {field: 'customerSkuName', title: '物料名称'}
                            , {field: 'customerSpecCode', title: '规格码'}
                            , {
                                field: 'orderProEnclosureList', title: '附件', templet: d => {
                                    let orderProEnclosureListHtml = '';
                                    d.orderProEnclosureList.forEach((item, index) => {
                                        orderProEnclosureListHtml += '<a href="' + item.fileUrl + ' target="_blank">' + item.fileName + '</a></br />'
                                    });
                                    return orderProEnclosureListHtml;
                                }
                            }
                            , {field: 'proUnitName', title: '单位'}
                            , {field: 'quantity', title: '数量'}
                            , {field: 'proRemark', title: '备注'}
                            , {
                                align: 'center', title: '操作', templet: d => {
                                    let selectHTML = '';
                                    selectHTML += '<select name="status" lay-filter="status" lay-verify="required">';
                                    selectHTML += '<option value="">请选择</option>';
                                    selectHTML += `<option value="accepted" ${d.status == 'accepted' ? 'selected=""' : ''}>受理</option>`;
                                    selectHTML += `<option value="refuse" ${d.status == 'refuse' ? 'selected=""' : ''}>不受理</option>`;
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                        ]],
                        done: function (res, curr, count) {
                            form.on("select(status)", function (data) {
                                if (data.value == 'accepted') {
                                    $('#inquiryOrderExamineOrderProReviewBox').show({duration: 300});
                                } else {
                                    $('#inquiryOrderExamineOrderProReviewBox').hide({duration: 300});
                                    inquiryOrderExamineOrderProReviewTbData = [];
                                    table.reload('inquiryOrderExamineOrderProReviewTable', {data: inquiryOrderExamineOrderProReviewTbData});
                                }
                            });
                            if (_type == 'details') {
                                $('[lay-filter="status"]').attr('disabled', 'disabled');
                                $('#inquiryOrderExamineOrderProReviewAdd').hide();
                                $('button[lay-filter="inquiryOrderExamineSubmit"]').hide();
                                $('#inquiryOrderExamineOrderProReviewBox').show();
                                form.render('select');
                            }
                        }
                    });

                    // 请求 评审环节下拉框数据
                    admin.reqSync('enterprise/sell/admin/order/findReview', {type: InquiryOrderDetailsFormData.orderType}, res => {
                        if (res.code === 200) {
                            reviewProcessIdData = [];
                            reviewProcessIdData = res.data;
                        }
                    }, 'get');

                    if (_type == 'details') {
                        data.orderProReviewList.forEach((item, index) => {
                            item.reviewProcessIdData = reviewProcessIdData;
                            admin.reqSync('enterprise/sell/admin/orderReviewProcessCompany/getRoleData', {processId: item.reviewProcessId}, res => {
                                if (res.code === 200) {
                                    item.reviewPostIdData = res.data;
                                }
                            }, 'get');
                            admin.reqSync('user/admin/user/list', {postId: item.reviewPostId}, res => {
                                if (res.code === 200) {
                                    item.reviewerIdData = res.data;
                                }
                            }, 'get');

                            inquiryOrderExamineOrderProReviewTbData.push(item)
                        });

                    } else {
                        // 添加评审环节
                        $('#inquiryOrderExamineOrderProReviewAdd').click(function () {
                            let inquiryOrderExamineOrderProReviewTbDataObj = {};
                            inquiryOrderExamineOrderProReviewTbDataObj.index = inquiryOrderExamineOrderProReviewTbData.length;
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewProcessIdData = reviewProcessIdData;
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewProcessId = '';
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewProcessName = '';
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewPostIdData = [];
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewPostId = '';
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewPostName = '';
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewerIdData = [];
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewerId = '';
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewerName = '';
                            inquiryOrderExamineOrderProReviewTbDataObj.reviewEndTime = '';
                            inquiryOrderExamineOrderProReviewTbDataObj.remark = '';
                            inquiryOrderExamineOrderProReviewTbData.push(inquiryOrderExamineOrderProReviewTbDataObj);
                            table.reload('inquiryOrderExamineOrderProReviewTable', {data: inquiryOrderExamineOrderProReviewTbData});
                        });
                    }

                    let inquiryOrderExamineOrderProReviewTb = table.render({
                        elem: '#inquiryOrderExamineOrderProReviewTable',
                        data: inquiryOrderExamineOrderProReviewTbData,
                        page: false,
                        cellMinWidth: 100,
                        height: 500,
                        cols: [[
                            {
                                field: 'reviewProcessId', title: '评审环节', width: '200', templet: d => {
                                    let selectHTML = '';
                                    selectHTML += '<select name="reviewProcessId" lay-filter="reviewProcessId" lay-verify="required">';
                                    selectHTML += '<option value="">评审环节</option>';
                                    d.reviewProcessIdData.forEach(item => {
                                        if (d.reviewProcessId == item.id) {
                                            selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                        } else {
                                            selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';

                                        }
                                    });
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'reviewPostId', title: '评审岗位', width: '200', templet: d => {
                                    let selectHTML = '';
                                    selectHTML += '<select name="reviewPostId" lay-filter="reviewPostId" lay-verify="required">';
                                    selectHTML += '<option value="">评审岗位</option>';
                                    d.reviewPostIdData.forEach(item => {
                                        if (d.reviewPostId == item.id) {
                                            selectHTML += '<option value="' + item.id + '" selected="">' + item.name + '</option>';
                                        } else {
                                            selectHTML += '<option value="' + item.id + '">' + item.name + '</option>';

                                        }
                                    });
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'reviewerId', title: '评审人员', width: '200', templet: d => {
                                    let selectHTML = '';
                                    selectHTML += '<select name="reviewerId" lay-filter="reviewerId" lay-verify="required">';
                                    selectHTML += '<option value="">评审人员</option>';
                                    d.reviewerIdData.forEach(item => {
                                        if (d.reviewerId == item.id) {
                                            selectHTML += '<option value="' + item.id + '" selected="">' + item.username + '</option>';
                                        } else {
                                            selectHTML += '<option value="' + item.id + '">' + item.username + '</option>';

                                        }
                                    });
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'reviewEndTime', title: '截至时间', width: '200', templet: d => {
                                    let reviewEndTimeHtml = '<input class="layui-input" id="reviewEndTime' + d.index + '" name="reviewEndTime" value="' + d.reviewEndTime + '"/>';
                                    return reviewEndTimeHtml;
                                }
                            }
                            , {
                                field: ' remark',
                                title: '评审备注',
                                width: '400',
                                templet: d => '<input type="text" name="reviewRemark" class="layui-input" value="' + d.remark + '">'
                            },
                            _type == 'details' ? '' : {
                                align: 'center',
                                toolbar: '#inquiryOrderInformationFormBar',
                                title: '操作'
                            }
                        ]],
                        done: function (res, curr, count) {
                            for (let i = 0; i < count; i++) {
                                laydate.render({
                                    elem: '#reviewEndTime' + res.data[i].index,
                                    type: 'datetime',
                                    index: res.data[i].index,
                                    done: function (value, date) {
                                        inquiryOrderExamineOrderProReviewTbData[this.index].reviewEndTime = value;
                                    }
                                });
                            }
                            if (_type == 'details') {
                                $('div[lay-id="inquiryOrderExamineOrderProReviewTable"] input').attr('disabled', 'disabled');
                                $('div[lay-id="inquiryOrderExamineOrderProReviewTable"] select').attr('disabled', 'disabled');
                                form.render('select');
                            }
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(inquiryOrderExamineOrderProReviewTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'delete') { //删除
                            inquiryOrderExamineOrderProReviewTbData.splice(obj.tr.index(), 1);
                            table.reload('inquiryOrderExamineOrderProReviewTable', {data: inquiryOrderExamineOrderProReviewTbData});
                        }
                    });

                    form.on("select", function (data) {
                        if ($(data.elem).attr('name') == 'reviewProcessId') {
                            if (data.value && data.value != '') {
                                // 请求 评审岗位下拉框数据
                                admin.reqSync('enterprise/sell/admin/orderReviewProcessCompany/getRoleData', {processId: data.value}, res => {
                                    if (res.code === 200) {
                                        inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewPostIdData = res.data;
                                    }
                                }, 'get');
                            } else {
                                inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewPostIdData = [];
                                inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewerIdData = [];
                            }
                            inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewProcessId = data.value;
                            inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewProcessName = data.elem[data.elem.selectedIndex].text;
                            table.reload('inquiryOrderExamineOrderProReviewTable', {data: inquiryOrderExamineOrderProReviewTbData});

                        } else if ($(data.elem).attr('name') == 'reviewPostId') {
                            // 请求 评审人员下拉框数据
                            if (data.value && data.value != '') {
                                admin.reqSync('user/admin/user/list', {postId: data.value}, res => {
                                    if (res.code === 200) {
                                        inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewerIdData = res.data;
                                    }
                                }, 'get');
                            } else {
                                inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewerIdData = [];
                            }
                            inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewPostId = data.value;
                            inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewPostName = data.elem[data.elem.selectedIndex].text;
                            table.reload('inquiryOrderExamineOrderProReviewTable', {data: inquiryOrderExamineOrderProReviewTbData});

                        } else if ($(data.elem).attr('name') == 'reviewerId') {
                            inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewerId = data.value;
                            inquiryOrderExamineOrderProReviewTbData[$(data.elem).parents('tr').index()].reviewerName = data.elem[data.elem.selectedIndex].text;
                        }
                    });

                    $("body").delegate("[lay-id='inquiryOrderExamineOrderProReviewTable'] input[name='reviewRemark']", "change", function () {
                        if (inquiryOrderExamineOrderProReviewTbData[$(this).parents('tr').index()]) {
                            inquiryOrderExamineOrderProReviewTbData[$(this).parents('tr').index()].remark = $(this).val().trim();
                        }
                    });

                    //保存
                    form.on('submit(inquiryOrderExamineSubmit)', function (d) {
                        let objData = {}, objDataList = [];
                        layer.load(2);
                        new Promise((resolve, reject) => {
                            inquiryOrderExamineOrderProReviewTbData.forEach((item, index) => {
                                objDataList[index] = {};
                                objDataList[index].reviewProcessId = item.reviewProcessId;
                                objDataList[index].reviewProcessName = item.reviewProcessName;
                                objDataList[index].reviewPostId = item.reviewPostId;
                                objDataList[index].reviewPostName = item.reviewPostName;
                                objDataList[index].reviewerId = item.reviewerId;
                                objDataList[index].reviewerName = item.reviewerName;
                                objDataList[index].reviewEndTime = item.reviewEndTime;
                                objDataList[index].remark = item.remark;
                            });
                            resolve(objDataList);
                        }).then(r => {
                            objData.status = d.field.status;
                            objData.id = data.id;
                            objData.orderId = InquiryOrderDetailsFormData.id;
                            if (d.field.status == 'accepted') {
                                if (r.length > 0) {
                                    objData.orderProReviewList = r;
                                } else {
                                    layer.msg('请添加评环节', {icon: '2'});
                                    layer.closeAll('loading');
                                    return false;
                                }
                            } else {
                                objData.orderProReviewList = [];
                            }


                            admin.req('enterprise/sell/admin/orderPro/update', JSON.stringify(objData), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    InquiryOrderDetailsFormData.orderProList.forEach(function (item) {
                                        if (item.id == data.id) {
                                            item.statusDesc = objData.status == 'accepted' ? '已受理' : '不受理';
                                            item.status = objData.status;
                                            table.reload('inquiryOrderDetailsTable', {data: InquiryOrderDetailsFormData.orderProList});
                                        }
                                    });
                                    table.reload('orderTable');
                                    layer.close(inquiryOrderExaminePop);
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'PUT', true, 'application/json; charset=utf-8');
                        });
                        return false;
                    });

                }
            });
        }

        // 询价订单 评审
        function showInquiryOrderReviewForm(data, _type) {
            let inquiryOrderReviewPop = admin.open({
                type: 1,
                area: ['1450px', '750px'],
                offset: '75px',
                title: _type == 'review' ? '订单评审' : '订单评审详情',
                content: $('#inquiryOrderReviewForm').html(),
                success: function () {
                    // 评审环节数据
                    let inquiryReviewResultTableData = '';

                    form.val('inquiryOrderReviewForm', InquiryOrderDetailsFormData);

                    // 物料信息
                    let inquiryOrderExamineTb = table.render({
                        elem: '#inquiryOrderReviewTable',
                        data: [data],
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'customerSkuItem', title: '客户SKU料号'}
                            , {field: 'customerSkuName', title: '物料名称'}
                            , {field: 'customerSpecCode', title: '规格码'}
                            , {
                                field: 'orderProEnclosureList', title: '附件', templet: d => {
                                    let orderProEnclosureListHtml = '';
                                    d.orderProEnclosureList.forEach((item, index) => {
                                        orderProEnclosureListHtml += '<a href="' + item.fileUrl + ' target="_blank">' + item.fileName + '</a></br />'
                                    });
                                    return orderProEnclosureListHtml;
                                }
                            }
                            , {field: 'proUnitName', title: '单位'}
                            , {field: 'quantity', title: '数量'}
                            , {field: 'proRemark', title: '备注'}
                            , {field: 'statusDesc', title: '状态'}
                        ]],
                        done: function (res, curr, count) {

                        }
                    });

                    // 评审环节
                    let inquiryReviewLinkTb = table.render({
                        elem: '#inquiryReviewLinkTable',
                        data: data.orderProReviewList,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'reviewProcessName', title: '评审环节'}
                            , {field: 'reviewPostName', title: '评审岗位'}
                            , {field: 'reviewPostName', title: '评审人员'}
                            , {field: 'reviewEndTime', title: '截至时间'}
                            , {field: 'remark', title: '评审备注'}
                            , {field: 'statusDesc', title: '状态'}
                            , {field: 'resultDesc', title: '评审结果'}
                            , {field: 'reviewDesc', title: '结果描述'}
                            , {field: 'reviewTime', title: '评审用时'}
                        ]],
                        done: function (res, curr, count) {

                        }
                    });

                    if (_type == 'review') {
                        inquiryReviewResultTableData = [{
                            finalResult: '',
                            suggestLowestPrice: '',
                            suggestPrice: '',
                            discountPrice: '',
                            offerRemark: ''
                        }];
                    } else {
                        inquiryReviewResultTableData = [data]
                    }

                    //终审结果
                    let inquiryReviewResultTb = table.render({
                        elem: '#inquiryReviewResultTable',
                        data: inquiryReviewResultTableData,
                        page: false,
                        cellMinWidth: 100,
                        height: 250,
                        cols: [[
                            {
                                field: 'finalResult', title: '是否接单', templet: d => {
                                    let selectHTML = '';
                                    selectHTML += '<select name="finalResult" lay-filter="finalResult" lay-verify="required">';
                                    selectHTML += '<option value="">是否接单</option>';
                                    selectHTML += `<option value="pass" ${d.finalResult == 'pass' ? 'selected=""' : ''}>接单</option>`;
                                    selectHTML += `<option value="fail" ${d.finalResult == 'fail' ? 'selected=""' : ''}>不接单</option>`;
                                    selectHTML += '</select>';
                                    return selectHTML
                                }
                            }
                            , {
                                field: 'suggestLowestPrice',
                                title: '建议最低单价',
                                templet: d => '<input type="text" name="suggestLowestPrice" class="layui-input" value="' + d.suggestLowestPrice + '">'
                            }
                            , {
                                field: 'suggestPrice', title: '建议单价',
                                templet: d => '<input type="text" name="suggestPrice" class="layui-input" value="' + d.suggestPrice + '">'
                            }
                            , {
                                field: 'discountPrice', title: '优惠单价',
                                templet: d => '<input type="text" name="discountPrice" class="layui-input" value="' + d.discountPrice + '">'
                            }
                            , {
                                field: 'offerRemark', title: '备注说明',
                                templet: d => '<input type="text" name="offerRemark" class="layui-input" value="' + d.offerRemark + '">'
                            }
                        ]],
                        done: function (res, curr, count) {
                            if (_type == 'details') {
                                $('div[lay-id="inquiryReviewResultTable"] input').attr('disabled', 'disabled');
                                $('div[lay-id="inquiryReviewResultTable"] select').attr('disabled', 'disabled');
                                $('button[lay-filter="inquiryOrderReviewSubmit"]').hide();
                                form.render('select');
                            }
                        }
                    });

                    form.on("select", function (data) {
                        if ($(data.elem).attr('name') == 'finalResult') {
                            inquiryReviewResultTableData[$(data.elem).parents('tr').index()].finalResult = data.value;
                        }
                    });

                    $("body").delegate("[lay-id='inquiryReviewResultTable'] input[name='suggestPrice']", "change", function () {
                        if (inquiryReviewResultTableData[$(this).parents('tr').index()]) {
                            inquiryReviewResultTableData[$(this).parents('tr').index()].suggestPrice = $(this).val().trim();
                        }
                    });

                    $("body").delegate("[lay-id='inquiryReviewResultTable'] input[name='suggestLowestPrice']", "change", function () {
                        if (inquiryReviewResultTableData[$(this).parents('tr').index()]) {
                            inquiryReviewResultTableData[$(this).parents('tr').index()].suggestLowestPrice = $(this).val().trim();
                        }
                    });

                    $("body").delegate("[lay-id='inquiryReviewResultTable'] input[name='discountPrice']", "change", function () {
                        if (inquiryReviewResultTableData[$(this).parents('tr').index()]) {
                            inquiryReviewResultTableData[$(this).parents('tr').index()].discountPrice = $(this).val().trim();
                        }
                    });

                    $("body").delegate("[lay-id='inquiryReviewResultTable'] input[name='offerRemark']", "change", function () {
                        if (inquiryReviewResultTableData[$(this).parents('tr').index()]) {
                            inquiryReviewResultTableData[$(this).parents('tr').index()].offerRemark = $(this).val().trim();
                        }
                    });

                    // 保存

                    form.on('submit(inquiryOrderReviewSubmit)', function (d) {
                        inquiryReviewResultTableData[0].id = data.id;
                        layer.load(2);
                        admin.req('enterprise/sell/admin/orderPro/update', JSON.stringify(inquiryReviewResultTableData[0]), function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                InquiryOrderDetailsFormData.orderProList.forEach(function (item) {
                                    if (item.id == data.id) {
                                        item.finalResult = inquiryReviewResultTableData[0].finalResult;
                                        table.reload('inquiryOrderDetailsTable', {data: InquiryOrderDetailsFormData.orderProList});
                                    }
                                });
                                table.reload('orderTable');
                                layer.close(inquiryOrderReviewPop);
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, 'PUT', true, 'application/json; charset=utf-8');
                        return false;
                    });
                }
            })
        }

        //询价订单 报价
        function showInquiryOrderOfferForm(data, _type) {
            admin.open({
                type: 1,
                area: ['1500px', '800px'],
                offset: '65px',
                title: '订单报价界面',
                content: $('#inquiryOrderOfferForm').html(),
                success: function () {
                    //   请求所属部门
                    /*admin.reqSync('user/admin/user/getUserInfoByUserId', {userId: data.creator}, res => {
                        if (res.code === 200) {
                            InquiryOrderDetailsFormData.departmentName = res.data.departmentName;
                        }
                    }, 'get');*/

                    form.val('inquiryOrderOfferForm', InquiryOrderDetailsFormData);
                    let inquiryOrderOffer = [];
                    data.orderProList.forEach((item, index) => {
                        if (item.offerStatus == 'wait') {
                            inquiryOrderOffer.push(item)
                        }
                    });
                    let inquiryOrderOfferTb = table.render({
                        elem: '#inquiryOrderOfferTable',
                        data: inquiryOrderOffer,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'checkbox'}
                            , {type: 'numbers', title: '序号'}
                            , {field: 'customerSkuItem', title: '客户SKU料号'}
                            , {field: 'customerSpecCode', title: '客户规格码'}
                            , {field: 'proUnitName', title: '单位'}
                            , {field: 'quantity', title: '数量'}
                            , {field: 'suggestLowestPrice', title: '建议最低单价'}
                            , {field: 'suggestPrice', title: '建议单价'}
                            , {field: 'offerStatusDesc', title: '状态'}
                            , {
                                field: 'offerMoney', title: '最新报价',
                                templet: d => '<input type="text" name="offerMoney" class="layui-input">'
                            }
                            , {
                                field: 'remark',
                                title: '报价备注',
                                templet: d => '<input type="text" name="remark" class="layui-input">'
                            }
                        ]],
                        done: function (res, curr, count) {

                        }
                    });

                    $("body").delegate("[lay-id='inquiryOrderOfferTable'] input[name='offerMoney']", "change", function () {
                        if (inquiryOrderOffer[$(this).parents('tr').index()]) {
                            inquiryOrderOffer[$(this).parents('tr').index()].offerMoney = $(this).val().trim();
                        }
                    });

                    $("body").delegate("[lay-id='inquiryOrderOfferTable'] input[name='remark']", "change", function () {
                        if (inquiryOrderOffer[$(this).parents('tr').index()]) {
                            inquiryOrderOffer[$(this).parents('tr').index()].remark = $(this).val().trim();
                        }
                    });

                    form.on('submit(inquiryOrderOfferSubmit)', function (d) {
                        let objData = {}, objDataList = [];
                        let checkStatus = table.checkStatus('inquiryOrderOfferTable');
                        new Promise((resolve, reject) => {
                            if (checkStatus.data.length > 0) {
                                checkStatus.data.forEach((item, index) => {
                                    objDataList[index] = {};
                                    objDataList[index].offerMoney = item.offerMoney;
                                    objDataList[index].remark = item.remark;
                                    objDataList[index].proId = item.id;
                                });
                                resolve(objDataList);
                            } else {
                                layer.msg('请选择报价物料', {icon: 2});
                            }

                        }).then(r => {
                            objData.orderId = data.id;
                            objData.orderOfferDetailList = r;
                            layer.load(2);
                            admin.req('enterprise/sell/admin/orderOffer/add', JSON.stringify(objData), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('orderTable');
                                    layer.closeAll('page');
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'POST', true, 'application/json; charset=utf-8');
                        });
                        return false;
                    });

                }
            })
        }

        //询价订单 报价记录
        function showInquiryOrderQuotationRecordForm(data) {
            admin.open({
                type: 1,
                area: ['1500px', '800px'],
                offset: '65px',
                title: '订单报价记录界面',
                content: $('#inquiryOrderQuotationRecordForm').html(),
                success: function () {
                    //   请求所属部门
                    /*admin.reqSync('user/admin/user/getUserInfoByUserId', {userId: data.creator}, res => {
                        if (res.code === 200) {
                            InquiryOrderDetailsFormData.departmentName = res.data.departmentName;
                        }
                    }, 'get');*/
                    form.val('inquiryOrderQuotationRecordForm', InquiryOrderDetailsFormData);

                    let inquiryOrderQuotationRecordTb = table.render({
                        elem: '#inquiryOrderQuotationRecordTable',
                        url: config.base + 'enterprise/sell/admin/orderOffer/list?orderId=' + data.id,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {field: 'code', title: '报价记录编号'}
                            , {field: 'creatorName', title: '报价人'}
                            , {field: 'roleName', title: '所属岗位'}
                            , {field: 'deptName', title: '所属部门'}
                            , {field: 'createTime', title: '报价时间'}
                            , {field: 'proNum', title: '报价物料数'}
                            , {field: 'totalMoney', title: '报价单总金额'}
                            , {field: 'remark', title: '报价备注'}
                            , {field: 'updateDuring', title: '更新时长'}
                            , {toolbar: '#inquiryOrderQuotationRecordBar', title: '操作'}
                        ]],
                        done: function (res, curr, count) {

                        }
                    });


                    table.on('tool(inquiryOrderQuotationRecordTable)', function (obj) {
                        let data = obj.data;
                        if (obj.event === 'details') { //详情
                            showInquiryOrderQuotationRecordDetailsForm(data);
                        } else if (obj.event === 'final') {
                            doFinal(data)
                        }
                    });
                }
            })
        }

        // 设为终版
        function doFinal(data) {
            layer.confirm('确定设为终版吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/sell/admin/orderOffer/finalEdition', {id: data.id}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        table.reload('inquiryOrderQuotationRecordTable');
                        table.reload('orderTable');
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'POST');
            });
        }

        //询价订单 报价记录 详情
        function showInquiryOrderQuotationRecordDetailsForm(data) {
            let inquiryOrderQuotationRecordDetailsPop = admin.open({
                type: 1,
                area: ['1450px', '750px'],
                offset: '85px',
                title: '订单报价记录详情界面',
                content: $('#inquiryOrderQuotationRecordDetailsForm').html(),
                success: function () {
                    let inquiryOrderQuotationRecordDetailsTableData = [];
                    form.val('inquiryOrderQuotationRecordDetailsForm', InquiryOrderDetailsFormData);
                    admin.reqSync('enterprise/sell/admin/orderOfferDetail/list', {offerId: data.id}, res => {
                        if (res.code === 200) {
                            inquiryOrderQuotationRecordDetailsTableData = res.data;
                        }
                    }, 'get');
                    let inquiryOrderQuotationRecordDetailsTb = table.render({
                        elem: '#inquiryOrderQuotationRecordDetailsTable',
                        data: inquiryOrderQuotationRecordDetailsTableData,
                        page: false,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'customerSkuItem', title: '客户SKU料号'}
                            , {field: 'customerSpecCode', title: '客户规格码'}
                            , {field: 'unitName', title: '单位'}
                            , {field: 'quantity', title: '数量'}
                            , {field: 'suggestLowestPrice', title: '建议最低单价'}
                            , {field: 'suggestPrice', title: '建议单价'}
                            , {field: 'discountPrice', title: '优惠单价'}
                            , {field: 'statusDesc', title: '状态'}
                            , {field: 'lastMoney', title: '上次报价'}
                            , {
                                field: 'offerMoney',
                                title: '报价',
                                templet: d => {
                                    if (!data.whetherFinal) {
                                        return '<input type="text" name="offerMoney" class="layui-input" value="' + d.offerMoney + '" lay-verify="number">'
                                    } else {
                                        return d.offerMoney
                                    }
                                }
                            }
                            , {
                                field: 'remark',
                                title: '报价备注',
                                templet: d => {
                                    if (!data.whetherFinal) {
                                        return '<input type="text" name="remark" class="layui-input" value="' + d.remark + '">'
                                    } else {
                                        return d.remark
                                    }
                                }
                            }

                        ]],
                        done: function (res, curr, count) {

                        }
                    });


                    $("body").delegate("[lay-id='inquiryOrderQuotationRecordDetailsTable'] input[name='offerMoney']", "change", function () {
                        if (inquiryOrderQuotationRecordDetailsTableData[$(this).parents('tr').index()]) {
                            inquiryOrderQuotationRecordDetailsTableData[$(this).parents('tr').index()].offerMoney = $(this).val().trim();
                        }
                    });

                    $("body").delegate("[lay-id='inquiryOrderQuotationRecordDetailsTable'] input[name='remark']", "change", function () {
                        if (inquiryOrderQuotationRecordDetailsTableData[$(this).parents('tr').index()]) {
                            inquiryOrderQuotationRecordDetailsTableData[$(this).parents('tr').index()].remark = $(this).val().trim();
                        }
                    });
                    if (data.whetherFinal) {
                        $('button[lay-filter="inquiryOrderQuotationRecordDetailsSubmit"]').hide();
                    }

                    form.on('submit(inquiryOrderQuotationRecordDetailsSubmit)', function (d) {
                        let objData = {}, objDataList = [];
                        new Promise((resolve, reject) => {
                            inquiryOrderQuotationRecordDetailsTableData.forEach((item, index) => {
                                objDataList[index] = {};
                                objDataList[index].offerMoney = item.offerMoney;
                                objDataList[index].remark = item.remark;
                                objDataList[index].id = item.id;
                                objDataList[index].proId = item.proId;
                            });
                            resolve(objDataList);
                        }).then(r => {
                            objData.id = data.id;
                            objData.orderOfferDetailList = r;
                            layer.load(2);
                            admin.req('enterprise/sell/admin/orderOffer/update ', JSON.stringify(objData), function (res) {
                                layer.closeAll('loading');
                                if (res.code == 200) {
                                    layer.msg(res.msg, {icon: 1});
                                    table.reload('inquiryOrderQuotationRecordTable');
                                    layer.close(inquiryOrderQuotationRecordDetailsPop);
                                } else {
                                    layer.msg(res.msg, {icon: 2});
                                }
                            }, 'put', true, 'application/json; charset=utf-8');
                        });
                        return false;
                    });

                }
            })
        }

        // 合同
        function showInquiryOrderContractForm(data) {
            let inquiryOrderQuotationRecordDetailsPop = admin.open({
                type: 1,
                area: ['1500px', '800px'],
                offset: '85px',
                title: '合同',
                content: $('#inquiryOrderContractForm').html(),
                success: function () {
                    let inquiryOrderContractFormTb = table.render({
                        elem: '#inquiryOrderContractFormTable',
                        url: config.base + 'enterprise/sell/admin/customerContract/list?subjectId=' + data.customerId,
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers', title: '序号'}
                            , {field: 'code', title: '合同编号'}
                            , {field: 'typeDesc', title: '合同主体类型'}
                            , {field: '', title: '关联订单数'}
                            , {field: 'companyName', title: '供应商名称'}
                            , {field: 'contractCategoryName', title: '合同分类'}
                            , {field: 'createTime', title: '创建时间'}
                            , {field: 'contactName', title: '供应商签约人'}
                            , {field: 'amount', title: '签约金额'}
                            , {field: 'attachment', title: '合同附件', toolbar: '#viewAttachmentBar'}
                            , {field: 'statusDesc', title: '合同状态'}
                            , {
                                field: '',
                                title: '操作',
                                width: '150',
                                templet: d => {
                                    if (data.contractId == 0) {
                                        return '<a class="layui-btn layui-btn-xs" lay-event="preservation">保存</a>'
                                    } else {
                                        return '<a class="layui-btn layui-btn-xs" lay-event="view">详情</a> ' +
                                            '<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="changeRecord">变更记录</a>'
                                    }
                                }
                            }
                        ]],
                        done: function (res, curr, count) {
                            if (data.contractId == 0) {
                                $('#contractBtnAdd').show();
                            } else {
                                $('#contractBtnAdd').hide();
                            }
                        },
                        parseData: function (res) {
                            if (data.contractId == 0) {
                                return {
                                    code: res.code,
                                    count: res.count,
                                    currentTotal: res.currentTotal,
                                    data: res.data,
                                    msg: res.msg,
                                    settingTotal: res.settingTotal,
                                    totalFlag: res.totalFlag,

                                }
                            } else {
                                let resData = [];
                                res.data.forEach(item => {
                                    if (item.id == data.contractId) {
                                        resData.push(item)
                                    }
                                });
                                return {
                                    code: res.code,
                                    count: res.count,
                                    currentTotal: res.currentTotal,
                                    data: resData,
                                    msg: res.msg,
                                    settingTotal: res.settingTotal,
                                    totalFlag: res.totalFlag,

                                }
                            }
                        }
                    });

                    // 工具条点击事件
                    table.on('tool(inquiryOrderContractFormTable)', function (obj) {
                        let contractData = obj.data;
                        if (obj.event === 'viewAttachment') { // 查看附件
                            showViewAttachmentModel(contractData);
                        } else if (obj.event === 'preservation') {  // 保存(绑定合同)
                            layer.confirm('确定使用当前合同吗？', {
                                offset: '65px',
                                skin: 'layui-layer-admin'
                            }, function (i) {
                                layer.close(i);
                                layer.load(2);
                                admin.req('enterprise/sell/admin/order/update', JSON.stringify({
                                    id: data.id,
                                    contractId: contractData.id
                                }), function (res) {
                                    layer.closeAll('loading');
                                    if (res.code == 200) {
                                        layer.msg(res.msg, {icon: 1});
                                        data.contractId = contractData.id;
                                        if (contractData.status == 'hasSign') {
                                            admin.req('enterprise/sell/admin/order/submit', {
                                                id: data.id,
                                                type: 6
                                            }, function (res) {
                                                if (res.code == 200) {
                                                    layer.msg(res.msg + ',订单已转为正是订单', {icon: 1});
                                                    layer.close(inquiryOrderQuotationRecordDetailsPop);
                                                    table.reload('inquiryOrderContractFormTable');
                                                    table.reload('orderTable');
                                                }
                                            }, 'POST');
                                        } else {
                                            table.reload('inquiryOrderContractFormTable');
                                            table.reload('orderTable');
                                        }
                                    } else {
                                        layer.msg(res.msg, {icon: 2});
                                    }
                                }, 'put', true, 'application/json; charset=utf-8');
                            });
                        } else if (obj.event === 'view') {
                            showViewModel(contractData)
                        } else if (obj.event === 'changeRecord') {
                            showChangeRecordModel(contractData)
                        }
                    });

                    $('#contractBtnAdd').click(function () {
                        showContractForm(data, 'add')
                    })

                }
            });
        }

        // 添加合同
        function showContractForm(data, _type, isRefresh) {
            let contractPop = admin.open({
                type: 1,
                area: '800px',
                offset: '65px',
                title: _type == 'edit' ? '修改合同' : '添加合同',
                content: $('#contractForm').html(),
                success: function () {
                    //自定义验证规则
                    form.verify({
                        decimal: [/^[0-9]*(\.[0-9]{1,2})?$/, '格式错误'],
                        contractCategoryId: function (value) {
                            if (value == "") {
                                return "请选择合同分类";
                            }
                        },
                        attachment: function (value) {
                            if (value == "") {
                                return "请上传附件";
                            }
                        }
                    });

                    // 获取合同主体类型
                    admin.req('enterprise/contract/admin/contractCategory/types', {}, function (res) {
                        if (200 == res.code) {
                            $.each(res.data, function (index, item) {
                                $("form select[name='type']").append(new Option(item.name, item.id));//往下拉菜单里添加元素
                            })
                            $("form select[name='type']").find("option").each(function (index, item) {
                                // 默认主体类型为供应商
                                if ($(item).val() == "client") {
                                    $(item).attr("selected", true);
                                }
                            })
                            form.render(); //菜单渲染 把内容加载进去
                        } else {
                            layer.msg('获取合同主体类型失败!', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                    var selectId = null;
                    if (_type == 'edit') {
                        if (data && data.contractCategoryId) {
                            selectId = data.contractCategoryId;
                        }
                    }

                    // 获取合同分类
                    admin.req('enterprise/contract/admin/contractCategory/getTreeData', {
                        selectId: selectId,
                        type: "client"
                    }, function (res) {
                        if (200 == res.code) {
                            xmSelect.render({
                                el: '#selectContractCategory',
                                model: {label: {type: 'text'}},
                                radio: true,
                                clickClose: true,
                                filterable: true,
                                tree: {
                                    show: true,
                                    strict: false,
                                    /*expandedKeys: [-1],*/
                                    expandedKeys: true,
                                },
                                tips: '顶级分类',
                                height: 'auto',
                                data() {
                                    return res.data;
                                },
                                on: function (data) {
                                    //被选中的select的id,如果没有 -1
                                    let contractCategoryId = data.arr.length > 0 ? data.change[0].value : "";
                                    $("input[name='contractCategoryId']").val(contractCategoryId);
                                },
                            });
                        } else {
                            layer.msg('获取合同分类失败!', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                    // 获取签约主体

                    $("form select[name='subjectId']").append(new Option(data.customerName, data.customerId));

                    // 获取客户签约人
                    admin.req('enterprise/sell/admin/contactInfo/list', {
                        limit: 99999,
                        selCustomerId: data.customerId
                    }, function (res) {
                        if (200 == res.code) {
                            $("form select[name='contactsId']").html("");
                            $("form select[name='contactsId']").append(new Option("请选择客户签约人", ""));//往下拉菜单里添加元素
                            $.each(res.data, function (index, item) {
                                $("form select[name='contactsId']").append(new Option(item.name + "(" + item.telephone + ")", item.id));//往下拉菜单里添加元素
                            });
                            form.render(); //菜单渲染 把内容加载进去
                            if (data && data.contactsId) {
                                form.val('contractForm', data);
                            }
                        } else {
                            layer.msg('获取客户签约人失败!', {icon: 2, time: 1000});
                        }
                    }, 'GET');


                    // 获取我方签约人
                    admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                        console.log(res.data);
                        if (200 == res.code) {
                            $("form select[name='contractor']").append(new Option("请选择我方签约人", ""));//往下拉菜单里添加元素
                            $.each(res.data, function (index, item) {
                                $("form select[name='contractor']").append(new Option(item.nickname + "(" + item.username + ")", item.id));//往下拉菜单里添加元素
                            })
                            form.render(); //菜单渲染 把内容加载进去
                            if (data && data.contractor) {
                                form.val('contractForm', data);
                            }
                        } else {
                            layer.msg('获取我方签约人失败!', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                    // 获取信息审批人
                    admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                        console.log(res.data);
                        if (200 == res.code) {
                            $("form select[name='approver']").append(new Option("请选择信息审批人", ""));//往下拉菜单里添加元素
                            $.each(res.data, function (index, item) {
                                $("form select[name='approver']").append(new Option(item.nickname + "(" + item.username + ")", item.id));//往下拉菜单里添加元素
                            })
                            form.render(); //菜单渲染 把内容加载进去
                            if (data && data.approver) {
                                form.val('contractForm', data);
                            }
                        } else {
                            layer.msg('获取信息审批人失败!', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                    // 上传附件
                    upload.render({
                        elem: '#addDevicePicBtn'
                        , url: config.upload_url + 'uploadFile'
                        , data: {}
                        , accept: 'file'
                        , exts: 'pdf'
                        , headers: {Authorization: 'Bearer ' + config.getToken()}
                        , done: function (res) {
                            if (res.code == 200) {
                                layer.msg(res.msg || "上传成功", {icon: 1});
                                let imagUrl = res.data.url;
                                var name = res.data.fileName;
                                $('#addHeaderImg').html('<div class="attachments">' +
                                    '<div><img src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' + name + '</span></div></div>');
                                $('#attachment').val(imagUrl);

                                $(".attachments").click(function () {
                                    var json = {};
                                    json.attachment = imagUrl;
                                    showViewAttachmentModel(json);
                                })
                            } else if (res.code == 502) {
                                return location.replace('admin/login.html');
                            } else {
                                layer.msg(res.msg || "上传失败", {icon: 2});
                            }
                        }
                    });
                    if (_type == 'edit') {
                        form.val('contractForm', data);
                    }

                    // 表单提交事件
                    form.on('submit(contractFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(_type == 'edit' ? 'enterprise/sell/admin/customerContract/update' : 'enterprise/sell/admin/customerContract/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                if (isRefresh) {
                                    admin.req('enterprise/sell/admin/customerContract/list', {'subjectId': data.customerId}, function (res) {
                                        if (res.code == 200) {
                                            loadSelectHtml(res.data, "选择合同", "contractId", 3, 'inquiryOrderInformationForm');
                                        }
                                    }, 'GET');
                                }else {
                                    table.reload('inquiryOrderContractFormTable');
                                }
                                layer.close(contractPop);
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, _type == 'edit' ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 查看附件
        function showViewAttachmentModel(data) {
            admin.open({
                type: 1,
                area: ['1150px', '700px'],
                offset: '65px',
                title: '查看附件',
                content: $('#viewAttachmentHtml').html(),
                success: function () {
                    if (data.attachment) {
                        PDFObject.embed(data.attachment, "#example1");
                    }
                }
            })
        }

        // 合同详情弹窗
        function showViewModel(data) {
            admin.open({
                type: 1,
                area: ['80%', '80%'],
                offset: '65px',
                title: '合同详情',
                content: $('#contractView').html(),
                success: function () {
                    // 查询我方签约人
                    admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                        console.log(res.data);
                        if (200 == res.code) {
                            $.each(res.data, function (index, item) {
                                if (item.id == data.contractor) {
                                    $("#contractorName").text("我方签约人：" + item.nickname + "(" + item.username + ")");
                                }
                            })
                        } else {
                            layer.msg('获取我方签约人失败!', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                    // 查询合同保管员
                    admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                        if (200 == res.code) {
                            $.each(res.data, function (index, item) {
                                if (item.id == data.keeper) {
                                    $("#keeperName").text("合同保管员：" + item.nickname + "(" + item.username + ")");
                                }
                            })
                        } else {
                            layer.msg('获取合同保管员失败!', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                    // 查询信息审批人
                    admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                        if (200 == res.code) {
                            $.each(res.data, function (index, item) {
                                if (item.id == data.approver) {
                                    $("#approverName").text("信息审批人：" + item.nickname + "(" + item.username + ")");
                                }
                            })
                        } else {
                            layer.msg('获取信息审批人失败!', {icon: 2, time: 1000});
                        }
                    }, 'GET');

                    $("#attachmentName").text("合同附件：" + data.attachment.substring(data.attachment.lastIndexOf("/") + 1));

                    laytpl(contractInfoHtml.innerHTML).render(data, function (html) {
                        $("#contractInfo").html(html);
                    });

                    if (data.attachment) {
                        PDFObject.embed(data.attachment, "#exampleView");
                    }
                }
            })
        }

        // 合同变更记录
        function showChangeRecordModel(data) {
            var supplierContract = data;
            admin.open({
                type: 1,
                area: ['80%', '80%'],
                offset: '65px',
                title: '合同变更记录',
                content: $('#contractChangeRecord').html(),
                success: function () {

                    // 是否显示添加合同变更记录按钮
                    isShowAddBtn(supplierContract);

                    // 渲染表格
                    var changeRecordInsTb = table.render({
                        elem: '#contractChangeRecordTable',
                        url: config.base + 'enterprise/sell/admin/customerContract/contractChangeRecordList',
                        where: {contractId: supplierContract.id},
                        page: true,
                        cellMinWidth: 100,
                        cols: [[
                            {type: 'numbers'}
                            , {field: 'code', title: '合同编号', width: 130}
                            , {field: 'typeDesc', title: '合同主体类型', width: 140}
                            , {field: 'companyName', title: '客户名称', width: 120}
                            , {field: 'contractCategoryName', title: '合同分类', width: 120}
                            , {field: 'createTime', title: '创建时间', width: 170}
                            , {field: 'contactName', title: '客户签约人', width: 120}
                            , {field: 'amount', title: '签约金额', width: 110}
                            , {field: 'attachment', title: '合同附件', width: 110, toolbar: '#viewAttachmentBar'}
                            , {field: 'statusDesc', title: '合同状态', width: 110}
                            , {align: 'center', toolbar: '#contractChangeRecordTableBar', title: '操作', width: 200}
                        ]],
                        done: function (res, curr, count) {

                        }
                    });

                    // 工具条点击事件
                    table.on('tool(contractChangeRecordTable)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'edit') { // 修改
                            showEditChangeRecordModel(data, 'edit');
                        } else if (obj.event === 'view') { // 详情
                            showViewModel(data);
                        } else if (obj.event === 'audit') { // 审核
                            showAuditModel(data);
                        } else if (obj.event === 'final') { // 终版
                            doFinal(data);
                        } else if (obj.event === 'viewAttachment') { // 查看附件
                            showViewAttachmentModel(data);
                        }
                    });

                    // 添加按钮点击事件
                    $('#contractChangeRecordBtnAdd').click(function () {
                        showEditChangeRecordModel();
                    });

                    // 显示编辑弹窗
                    function showEditChangeRecordModel(data) {
                        var contractChangeRecord = admin.open({
                            type: 1,
                            area: ['800px', '80%'],
                            offset: '65px',
                            title: data ? '修改合同变更记录' : '添加合同变更记录',
                            content: $('#contractChangeRecordForm').html(),
                            success: function () {
                                //自定义验证规则
                                form.verify({
                                    decimal: [/^[0-9]*(\.[0-9]{1,2})?$/, '格式错误'],
                                    contractCategoryId: function (value) {
                                        if (value == "") {
                                            return "请选择合同分类";
                                        }
                                    },
                                    attachment: function (value) {
                                        if (value == "") {
                                            return "请上传附件";
                                        }
                                    }
                                })

                                // 签约时间
                                laydate.render({
                                    elem: '#signingTime',
                                    type: 'date'
                                });

                                // 交货时间
                                laydate.render({
                                    elem: '#deliveryTimeChangeRecord',
                                    type: 'date'
                                });

                                var selectId = null;
                                if (supplierContract && supplierContract.contractCategoryId) {
                                    selectId = supplierContract.contractCategoryId;
                                }

                                if (data && data.contractCategoryId) {
                                    selectId = data.contractCategoryId;
                                }

                                // 获取合同分类
                                admin.req('enterprise/contract/admin/contractCategory/getTreeData', {
                                    selectId: selectId,
                                    type: "client"
                                }, function (res) {
                                    if (200 == res.code) {
                                        xmSelect.render({
                                            el: '#selectContractCategoryChangeRecord',
                                            model: {label: {type: 'text'}},
                                            radio: true,
                                            clickClose: true,
                                            filterable: true,
                                            tree: {
                                                show: true,
                                                strict: false,
                                                /*expandedKeys: [-1],*/
                                                expandedKeys: true,
                                            },
                                            tips: '顶级分类',
                                            height: 'auto',
                                            data() {
                                                return res.data;
                                            },
                                            on: function (data) {
                                                //被选中的select的id,如果没有 -1
                                                let contractCategoryId = data.arr.length > 0 ? data.change[0].value : "";
                                                $("input[name='contractCategoryId']").val(contractCategoryId);
                                            },
                                        });
                                    } else {
                                        layer.msg('获取合同分类失败!', {icon: 2, time: 1000});
                                    }
                                }, 'GET');

                                var selCustomerId = null;
                                if (supplierContract && supplierContract.subjectId) {
                                    selCustomerId = supplierContract.subjectId;
                                }
                                if (data && data.subjectId) {
                                    selCustomerId = data.subjectId;
                                }
                                if (selCustomerId) {
                                    // 获取客户签约人
                                    admin.req('enterprise/sell/admin/contactInfo/list', {
                                        limit: 99999,
                                        selCustomerId: selCustomerId
                                    }, function (res) {
                                        if (200 == res.code) {
                                            $("form select[name='contactsId']").html("");
                                            $("form select[name='contactsId']").append(new Option("请选择客户签约人", ""));//往下拉菜单里添加元素
                                            $.each(res.data, function (index, item) {
                                                $("form select[name='contactsId']").append(new Option(item.name + "(" + item.telephone + ")", item.id));//往下拉菜单里添加元素
                                            });
                                            form.render(); //菜单渲染 把内容加载进去
                                            if (data && data.contactsId) {
                                                form.val('contractChangeRecordForm', data);
                                            } else {
                                                form.val('contractChangeRecordForm', supplierContract);
                                            }
                                        } else {
                                            layer.msg('获取客户签约人失败!', {icon: 2, time: 1000});
                                        }
                                    }, 'GET');
                                }


                                // 获取我方签约人
                                admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                                    if (200 == res.code) {
                                        $("form select[name='contractor']").append(new Option("请选择我方签约人", ""));//往下拉菜单里添加元素
                                        $.each(res.data, function (index, item) {
                                            $("form select[name='contractor']").append(new Option(item.nickname + "(" + item.username + ")", item.id));//往下拉菜单里添加元素
                                        })
                                        form.render(); //菜单渲染 把内容加载进去
                                        if (data && data.contractor) {
                                            form.val('contractChangeRecordForm', data);
                                        } else {
                                            form.val('contractChangeRecordForm', supplierContract);
                                        }
                                    } else {
                                        layer.msg('获取我方签约人失败!', {icon: 2, time: 1000});
                                    }
                                }, 'GET');

                                // 获取信息审批人
                                admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                                    if (200 == res.code) {
                                        $("form select[name='approver']").append(new Option("请选择信息审批人", ""));//往下拉菜单里添加元素
                                        $.each(res.data, function (index, item) {
                                            $("form select[name='approver']").append(new Option(item.nickname + "(" + item.username + ")", item.id));//往下拉菜单里添加元素
                                        })
                                        form.render(); //菜单渲染 把内容加载进去
                                        if (data && data.approver) {
                                            form.val('contractChangeRecordForm', data);
                                        } else {
                                            form.val('contractChangeRecordForm', supplierContract);
                                        }
                                    } else {
                                        layer.msg('获取信息审批人失败!', {icon: 2, time: 1000});
                                    }
                                }, 'GET');

                                // 上传附件
                                upload.render({
                                    elem: '#addDevicePicBtnChangeRecord'
                                    , url: config.upload_url + 'uploadFile'
                                    , data: {}
                                    , accept: 'file'
                                    , exts: 'pdf'
                                    , headers: {Authorization: 'Bearer ' + config.getToken()}
                                    , done: function (res) {
                                        if (res.code == 200) {
                                            layer.msg(res.msg || "上传成功", {icon: 1});
                                            let imagUrl = res.data.url;
                                            var name = res.data.fileName;
                                            $('#addHeaderImgChangeRecord').html('<div class="attachments">' +
                                                '<div><img src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' + name + '</span></div></div>');
                                            $('#attachmentChangeRecord').val(imagUrl);

                                            $(".attachments").click(function () {
                                                var json = {};
                                                json.attachment = imagUrl;
                                                showViewAttachmentModel(json);
                                            })
                                        } else if (res.code == 502) {
                                            return location.replace('admin/login.html');
                                        } else {
                                            layer.msg(res.msg || "上传失败", {icon: 2});
                                        }
                                    }
                                });

                                var attachment = "";

                                if (supplierContract && supplierContract.attachment) {
                                    attachment = supplierContract.attachment;
                                }
                                if (data && data.attachment) {
                                    attachment = data.attachment;
                                }

                                if (attachment != "") {
                                    var name = attachment.substring(attachment.lastIndexOf("/") + 1);
                                    // onclick="previewFile(\''+name+'\', \''+attachment+'\')"
                                    $('#addHeaderImgChangeRecord').html('<div class="attachments">' +
                                        '<div><img src="../../../admin/assets/images/attachmentsIcon/pdf.png"><span class="file-a">' + name + '</span></div></div>');
                                    $('#attachmentChangeRecord').val(attachment);

                                    $(".attachments").click(function () {
                                        var json = {};
                                        json.attachment = attachment;
                                        showViewAttachmentModel(json);
                                    })
                                }

                                // 获取合同保管员
                                admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                                    if (200 == res.code) {
                                        $("form select[name='keeper']").append(new Option("请选择合同保管员", ""));//往下拉菜单里添加元素
                                        $.each(res.data, function (index, item) {
                                            $("form select[name='keeper']").append(new Option(item.nickname + "(" + item.username + ")", item.id));//往下拉菜单里添加元素
                                        })
                                        form.render(); //菜单渲染 把内容加载进去
                                        if (data && data.keeper) {
                                            form.val('contractChangeRecordForm', data);
                                        }
                                    } else {
                                        layer.msg('获取合同保管员失败!', {icon: 2, time: 1000});
                                    }
                                }, 'GET');

                                form.on('switch(isFinal)', function (obj) {
                                    if (obj.elem.checked) {
                                        $("#content").show();
                                        $("#deliveryTimeChangeRecord").attr("lay-verify", "required").attr("required");
                                        $("input[name='address']").attr("lay-verify", "required").attr("required", true);
                                        $("select[name='keeper']").attr("lay-verify", "required").attr("required", true).attr("lay-search", true);
                                        form.render();
                                    } else {
                                        $("#content").hide();
                                        $("#deliveryTimeChangeRecord").removeAttr("lay-verify");
                                        $("input[name='address']").removeAttr("lay-verify");
                                        $("select[name='keeper']").removeAttr("lay-verify");
                                    }
                                });

                                if (data) {
                                    form.val('contractChangeRecordForm', data);
                                } else {
                                    form.val('contractChangeRecordForm', supplierContract);
                                }
                                // 表单提交事件
                                form.on('submit(contractChangeRecordFormSubmit)', function (d) {
                                    layer.load(2);
                                    var isFinal = $("form input[name='isFinal']").prop("checked");
                                    if (!isFinal) {
                                        d.field.isFinal = false;
                                    } else {
                                        d.field.isFinal = true;
                                    }
                                    if (d.field.signingTime) {
                                        d.field.signingTime = d.field.signingTime + " 00:00:00";
                                    }
                                    if (d.field.deliveryTime) {
                                        d.field.deliveryTime = d.field.deliveryTime + " 00:00:00";
                                    }
                                    d.field.contractId = supplierContract.id;
                                    admin.req(data ? 'enterprise/sell/admin/customerContract/updateContractChangeRecord' : 'enterprise/sell/admin/customerContract/addContractChangeRecord', d.field, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            isShowAddBtn(supplierContract);
                                            table.reload('contractChangeRecordTable');
                                            layer.close(contractChangeRecord);
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, data ? 'PUT' : 'POST');
                                    return false;
                                });
                            }
                        });
                    }

                    // 显示审核弹窗
                    function showAuditModel(data) {
                        var contractAudit = admin.open({
                            type: 1,
                            area: ['80%', '80%'],
                            offset: '65px',
                            title: '合同审核',
                            content: $('#contractAuditForm').html(),
                            success: function () {
                                // 查询我方签约人
                                admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                                    if (200 == res.code) {
                                        $.each(res.data, function (index, item) {
                                            if (item.id == data.contractor) {
                                                $("#contractorName").text("我方签约人：" + item.nickname + "(" + item.username + ")");
                                            }
                                        })
                                    } else {
                                        layer.msg('获取我方签约人失败!', {icon: 2, time: 1000});
                                    }
                                }, 'GET');

                                // 查询合同保管员
                                admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                                    if (200 == res.code) {
                                        $.each(res.data, function (index, item) {
                                            if (item.id == data.keeper) {
                                                $("#keeperName").text("合同保管员：" + item.nickname + "(" + item.username + ")");
                                            }
                                        })
                                    } else {
                                        layer.msg('获取合同保管员失败!', {icon: 2, time: 1000});
                                    }
                                }, 'GET');

                                // 查询信息审批人
                                admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                                    if (200 == res.code) {
                                        $.each(res.data, function (index, item) {
                                            if (item.id == data.approver) {
                                                $("#approverName").text("信息审批人：" + item.nickname + "(" + item.username + ")");
                                            }
                                        })
                                    } else {
                                        layer.msg('获取信息审批人失败!', {icon: 2, time: 1000});
                                    }
                                }, 'GET');


                                $("#attachmentNameAudit").text("合同附件：" + data.attachment.substring(data.attachment.lastIndexOf("/") + 1));

                                laytpl(contractInfoHtml.innerHTML).render(data, function (html) {
                                    $("#contractInfoAudit").html(html);
                                });

                                if (data.attachment) {
                                    PDFObject.embed(data.attachment, "#example1Audit");
                                }

                                form.val('contractAuditForm', data);

                                // 表单提交事件
                                form.on('submit(contractAuditFormSubmit)', function (d) {
                                    layer.load(2);
                                    d.field.status = $(this).data("status");
                                    admin.req('enterprise/sell/admin/customerContract/auditContractChangeRecord', d.field, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            isShowAddBtn(supplierContract);
                                            table.reload('contractChangeRecordTable');
                                            layer.close(contractAudit);
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, 'POST');
                                    return false;
                                });

                            }
                        })
                    }

                    // 终版
                    function doFinal(data) {
                        var contractFinal = admin.open({
                            type: 1,
                            area: ['800px'],
                            offset: '65px',
                            title: '合同终版确认',
                            content: $('#contractFinalForm').html(),
                            success: function () {
                                // 交货时间
                                laydate.render({
                                    elem: '#deliveryTimeFina',
                                    type: 'date'
                                });

                                // 获取合同保管员
                                admin.req('user/admin/user/list', {limit: 99999}, function (res) {
                                    if (200 == res.code) {
                                        $("form select[name='keeper']").append(new Option("请选择合同保管员", ""));//往下拉菜单里添加元素
                                        $.each(res.data, function (index, item) {
                                            $("form select[name='keeper']").append(new Option(item.nickname + "(" + item.username + ")", item.id));//往下拉菜单里添加元素
                                        })
                                        form.render(); //菜单渲染 把内容加载进去
                                    } else {
                                        layer.msg('获取合同保管员失败!', {icon: 2, time: 1000});
                                    }
                                }, 'GET');

                                form.val('contractFinalForm', data);

                                // 表单提交事件
                                form.on('submit(contractFinalFormSubmit)', function (d) {
                                    layer.load(2);
                                    if (d.field.deliveryTime) {
                                        d.field.deliveryTime = d.field.deliveryTime + " 00:00:00";
                                    }
                                    admin.req('enterprise/sell/admin/customerContract/setContractFinal', d.field, function (res) {
                                        layer.closeAll('loading');
                                        if (res.code == 200) {
                                            layer.msg(res.msg, {icon: 1});
                                            isShowAddBtn(supplierContract);
                                            table.reload('contractChangeRecordTable');
                                            table.reload('contractTable');
                                            layer.close(contractFinal);
                                            admin.req('enterprise/sell/admin/order/submit', {
                                                id: InquiryOrderDetailsFormData.id,
                                                type: 6
                                            }, function (res) {
                                                if (res.code == 200) {
                                                    layer.msg(res.msg + ',订单已转为正是订单', {icon: 1});
                                                    layer.closeAll('page');
                                                    table.reload('orderTable');
                                                }
                                            }, 'POST');
                                        } else {
                                            layer.msg(res.msg, {icon: 2});
                                        }
                                    }, 'POST');
                                    return false;
                                });

                            }
                        })

                    }

                }
            })
        }

        // 是否显示添加合同变更记录按钮
        function isShowAddBtn(data) {
            admin.req('enterprise/sell/admin/customerContract/isShowAddBtn', {id: data.id}, function (res) {
                if (200 == res.code) {
                    if (res.data) {
                        $("#contractChangeRecordBtnAdd").show();
                    } else {
                        $("#contractChangeRecordBtnAdd").hide();
                    }
                }
            }, 'GET');
        }


    });
</script>